然后我们尝试直接赋予jingyu2用户高大上的dba角色,理应一切ok了吧。
SYS@jyzhao1>grant dba to jingyu2; Grant succeeded.结果让人大跌眼镜,不可以!
JINGYU2@jyzhao1>select count(1) from jingyu3.t_jingyu3; select count(1) from jingyu3.t_jingyu3 * ERROR at line 1: ORA-00942: table or view does not exist JINGYU2@jyzhao1>create synonym t_jingyu3 for jingyu3.t_jingyu3; create synonym t_jingyu3 for jingyu3.t_jingyu3 * ERROR at line 1: ORA-01031: insufficient privileges至高无上的dba权限居然解决不了跨用户访问和创建同义词?
没搞错吧?
看到这里,你是怎么想的呢?
如果这时候你去尝试重新连接一个会话,会发现是可以成功实现需求的?
那么这样看来,oracle对于权限的赋予是立即生效的,但是角色却需要重新连接会话才会生效。
到这里还不甘心?
来看看旧的会话权限:
发现的确没有变化,那么有没有命令可以让旧的会话不重新连接就能够生效呢?
答案是肯定的,来看看 set role all 这条命令吧,可以在历史会话中执行,从而使得新赋予的角色生效。
另外,可以看到只赋予了DBA的角色,却额外包含了很多角色,如果此时查下权限会发现:
JINGYU2@jyzhao1>select * from session_privs; PRIVILEGE ---------------------------------------- ALTER SYSTEM AUDIT SYSTEM CREATE SESSION ALTER SESSION RESTRICTED SESSION CREATE TABLESPACE ALTER TABLESPACE MANAGE TABLESPACE DROP TABLESPACE UNLIMITED TABLESPACE CREATE USER BECOME USER ALTER USER DROP USER CREATE ROLLBACK SEGMENT ALTER ROLLBACK SEGMENT DROP ROLLBACK SEGMENT CREATE TABLE CREATE ANY TABLE ALTER ANY TABLE BACKUP ANY TABLE DROP ANY TABLE LOCK ANY TABLE COMMENT ANY TABLE SELECT ANY TABLE INSERT ANY TABLE UPDATE ANY TABLE DELETE ANY TABLE CREATE CLUSTER CREATE ANY CLUSTER ALTER ANY CLUSTER DROP ANY CLUSTER CREATE ANY INDEX ALTER ANY INDEX DROP ANY INDEX CREATE SYNONYM CREATE ANY SYNONYM DROP ANY SYNONYM CREATE PUBLIC SYNONYM DROP PUBLIC SYNONYM CREATE VIEW CREATE ANY VIEW DROP ANY VIEW CREATE SEQUENCE CREATE ANY SEQUENCE ALTER ANY SEQUENCE DROP ANY SEQUENCE PRIVILEGE ---------------------------------------- SELECT ANY SEQUENCE CREATE DATABASE LINK CREATE PUBLIC DATABASE LINK DROP PUBLIC DATABASE LINK CREATE ROLE DROP ANY ROLE GRANT ANY ROLE ALTER ANY ROLE AUDIT ANY ALTER DATABASE FORCE TRANSACTION FORCE ANY TRANSACTION CREATE PROCEDURE CREATE ANY PROCEDURE ALTER ANY PROCEDURE DROP ANY PROCEDURE EXECUTE ANY PROCEDURE CREATE TRIGGER CREATE ANY TRIGGER ALTER ANY TRIGGER DROP ANY TRIGGER CREATE PROFILE ALTER PROFILE DROP PROFILE ALTER RESOURCE COST ANALYZE ANY GRANT ANY PRIVILEGE CREATE MATERIALIZED VIEW CREATE ANY MATERIALIZED VIEW ALTER ANY MATERIALIZED VIEW DROP ANY MATERIALIZED VIEW CREATE ANY DIRECTORY DROP ANY DIRECTORY CREATE TYPE CREATE ANY TYPE ALTER ANY TYPE DROP ANY TYPE EXECUTE ANY TYPE UNDER ANY TYPE CREATE LIBRARY CREATE ANY LIBRARY ALTER ANY LIBRARY DROP ANY LIBRARY EXECUTE ANY LIBRARY CREATE OPERATOR CREATE ANY OPERATOR ALTER ANY OPERATOR PRIVILEGE ---------------------------------------- DROP ANY OPERATOR EXECUTE ANY OPERATOR CREATE INDEXTYPE CREATE ANY INDEXTYPE ALTER ANY INDEXTYPE DROP ANY INDEXTYPE UNDER ANY VIEW QUERY REWRITE GLOBAL QUERY REWRITE EXECUTE ANY INDEXTYPE UNDER ANY TABLE CREATE DIMENSION CREATE ANY DIMENSION ALTER ANY DIMENSION DROP ANY DIMENSION MANAGE ANY QUEUE ENQUEUE ANY QUEUE DEQUEUE ANY QUEUE CREATE ANY CONTEXT DROP ANY CONTEXT CREATE ANY OUTLINE ALTER ANY OUTLINE DROP ANY OUTLINE ADMINISTER RESOURCE MANAGER ADMINISTER DATABASE TRIGGER MERGE ANY VIEW ON COMMIT REFRESH RESUMABLE SELECT ANY DICTIONARY DEBUG CONNECT SESSION DEBUG ANY PROCEDURE FLASHBACK ANY TABLE GRANT ANY OBJECT PRIVILEGE CREATE EVALUATION CONTEXT CREATE ANY EVALUATION CONTEXT ALTER ANY EVALUATION CONTEXT DROP ANY EVALUATION CONTEXT EXECUTE ANY EVALUATION CONTEXT CREATE RULE SET CREATE ANY RULE SET ALTER ANY RULE SET DROP ANY RULE SET EXECUTE ANY RULE SET EXPORT FULL DATABASE IMPORT FULL DATABASE CREATE RULE CREATE ANY RULE PRIVILEGE ---------------------------------------- ALTER ANY RULE DROP ANY RULE EXECUTE ANY RULE ANALYZE ANY DICTIONARY ADVISOR CREATE JOB CREATE ANY JOB EXECUTE ANY PROGRAM EXECUTE ANY CLASS MANAGE SCHEDULER SELECT ANY TRANSACTION DROP ANY SQL PROFILE ALTER ANY SQL PROFILE ADMINISTER SQL TUNING SET ADMINISTER ANY SQL TUNING SET CREATE ANY SQL PROFILE MANAGE FILE GROUP MANAGE ANY FILE GROUP READ ANY FILE GROUP CHANGE NOTIFICATION CREATE EXTERNAL JOB CREATE ANY EDITION DROP ANY EDITION ALTER ANY EDITION CREATE ASSEMBLY CREATE ANY ASSEMBLY ALTER ANY ASSEMBLY DROP ANY ASSEMBLY EXECUTE ANY ASSEMBLY EXECUTE ASSEMBLY CREATE MINING MODEL CREATE ANY MINING MODEL DROP ANY MINING MODEL SELECT ANY MINING MODEL ALTER ANY MINING MODEL COMMENT ANY MINING MODEL CREATE CUBE DIMENSION ALTER ANY CUBE DIMENSION CREATE ANY CUBE DIMENSION DELETE ANY CUBE DIMENSION DROP ANY CUBE DIMENSION INSERT ANY CUBE DIMENSION SELECT ANY CUBE DIMENSION CREATE CUBE ALTER ANY CUBE CREATE ANY CUBE DROP ANY CUBE PRIVILEGE ---------------------------------------- SELECT ANY CUBE UPDATE ANY CUBE CREATE MEASURE FOLDER CREATE ANY MEASURE FOLDER DELETE ANY MEASURE FOLDER DROP ANY MEASURE FOLDER INSERT ANY MEASURE FOLDER CREATE CUBE BUILD PROCESS CREATE ANY CUBE BUILD PROCESS DROP ANY CUBE BUILD PROCESS UPDATE ANY CUBE BUILD PROCESS UPDATE ANY CUBE DIMENSION ADMINISTER SQL MANAGEMENT OBJECT FLASHBACK ARCHIVE ADMINISTER 202 rows selected.