Oracle 权限 role 权限 下次登录生效或者set role, sys permission 立即生效

grant或者revoke role时发现用户还是可以访问某些表,但是select any table 权限的添加和删除立即生效。

这就是role 和sys permisson的差异

select * from role_role permission

Applies To

All Users

Oracle Database - Enterprise Edition - Version 11.2.0.3 to Version 11.2.0.3

Oracle Database - Enterprise Edition - Version 8.1.7.4 to Version 11.1.0.7

Oracle Net Services - Version 19.1.0.0.0 to Version 19.1.0.0.0

Summary

  1. The alert.log is full with the following errors:

...

Tue Dec 30 18:15:42 2008

Errors in file d:\app\administrator\diag\rdbms\prod\prod\trace\prod_j000_3444.trc:

ORA-12012: error on auto execute of job 4002

ORA-28031: maximum of 148 enabled roles exceeded

Tue Dec 30 18:15:47 2008

Thread 1 cannot allocate new log, sequence 64

Checkpoint not complete

Current log# 3 seq# 63 mem# 0: D:\APP\ADMINISTRATOR\ORADATA\PROD\REDO03.LOG

Thread 1 advanced to log sequence 64 (LGWR switch)

Tue Dec 30 18:17:43 2008

Errors in file d:\app\administrator\diag\rdbms\prod\prod\trace\prod_j001_744.trc:

ORA-12012: error on auto execute of job 4005

ORA-28031: maximum of 148 enabled roles exceeded

...

Because of the ORA-28031 error no job is running. The user owning the job is able to connect to the database and furthermore has no errors while running the code executed via the job.

  1. An user gets the following error while connecting to the database:

SQL> conn testrole2

ERROR:

ORA-28031: maximum of 148 enabled roles exceeded

  1. While creating a queue table the following error occurs:

EXECUTE DBMS_AQADM.CREATE_QUEUE_TABLE (queue_table =>'QTEST', queue_payload_type => 'TTEST', multiple_consumers=> TRUE,compatible=>'10.2');

*

ERROR at line 1:

ORA-24166: evaluation context <schema>.AQ$_QTEST_V has errors

ORA-01925: maximum of 30 enabled roles exceeded

ORA-06512: at "SYS.DBMS_AQADM_SYS", line 2220

ORA-06512: at "SYS.DBMS_AQADM", line 58

ORA-06512: at line 1

Solution

  1. If this error does not occur while working with queues then check how many roles are going to be enabled in the user's session. Check all the default roles including those granted recursively:

SQL> select lpad(' ',2*level,' ')||granted_role

from dba_role_privs

where default_role='YES'

start with grantee='TESTROLE2' and default_role='YES'

connect by prior granted_role=grantee;

LPAD('',2*LEVEL,'')||GRANTED_ROLE


MYROLE

TROLE1

TROLE10

...

TROLE95

TROLE96

TROLE97

TROLE98

TROLE99

149 rows selected.

The list of distinct roles can be obtained with this query:

select distinct granted_role

from dba_role_privs

where default_role='YES'

start with grantee='<username>' and default_role='YES'

connect by prior granted_role=grantee

/

If there are indeed too many default roles being granted to that user then do the following:

A) Drop the roles that are not needed or merge some of the roles to reduce their total number.

B) Make sure that user has less than MAX_ENABLED_ROLES default roles(i.e. alter the user and specify a list of default roles)

C) Try to create all the custom roles while being connected with an user created for this purpose rather than creating them as SYS:

connect / as sysdba;

create user roleadmin identified by <password>;

grant create session, create role to roleadmin;

connect roleadmin;

... create roles...

connect / as sysdba;

alter user roleadmin default role none;

With this approach you avoid having too many roles granted automatically to SYS.

  1. When the error is encountered while working with queues one must take into account Bug 5523578 which is fixed in 10.2.0.5. Because of this bug, while working with the queue tables, the database counts the roles even if they are not default roles. In these situations the only solution is to count the roles granted to the user(even when they are not default roles) and if they are more than 148 to revoke some of them:

SQL> select lpad(' ',2*level,' ')||granted_role

from dba_role_privs

start with grantee='TESTROLE2'

connect by prior granted_role=grantee;

-- Note that the condition that checks whether the role is default has been removed

LPAD('',2*LEVEL,'')||GRANTED_ROLE


MYROLE

TROLE1

TROLE10

...

TROLE95

TROLE96

TROLE97

TROLE98

TROLE99

TROLE100

150 rows selected.

Cause

Error ORA-28031 occurs whenever one is attempting to enable more than 150 roles in the same session. A session is always enabling by default two roles(PUBLIC and the implicit role associated with the connected user). Besides these two roles, in the session, can be enabled up to 148 other roles. When a session is initializing, all default roles granted to the connecting user will be enabled. If the user is granted more than 148 default roles then the user will not be able to connect because of the ORA-28031 error. This does not apply for SYS normal connections. However when a user creates a job via DBMS_JOB or DBMS_SCHEDULER which runs as SYS the session created to execute the job will have all roles limits enabled.

It is important to note that we have to count the roles granted via a hierarchy(recursively) and not only the roles granted directly.

Usually an user is not granted (explicitly) so many default roles, however they can end up with so many roles because :

  1. There were many roles created by this user. Whenever a role gets created it is automatically granted to the user creating it :

SQL> conn / as sysdba

Connected.

SQL> create user testrole identified by ****;

User created.

SQL> grant create session, create role to ****;

Grant succeeded.

SQL> conn testrole

Connected.

SQL> select * from user_role_privs;

no rows selected

SQL> create role myrole1;

Role created.

SQL> select * from user_role_privs;

USERNAME GRANTED_ROLE ADM DEF OS_ROLE


TESTROLE MYROLE1 YES YES NO

The following example will show that an user gets this error although it is granted directly one role only:

SQL> create user testrole identified by *****;

User created.

SQL> create user testrole2 identified by ******;

User created.

SQL> grant create session, create role to testrole, testrole2;

Grant succeeded.

SQL> grant select on dba_role_privs to testrole;

Role granted.

SQL> conn testrole

Connected.

SQL> create role myrole;

Role created

begin

for rec in 1..148 loop

execute immediate 'create role trole'||rec;

execute immediate 'grant trole'||rec||' to myrole';

end loop;

end;

/

PL/SQL procedure successfully completed.

SQL> show user

USER is "TESTROLE"

SQL> grant myrole to testrole2;

Grant succeeded.

SQL> select count(*) from dba_role_privs where grantee='TESTROLE2';

COUNT(*)


1

SQL> conn testrole2

ERROR:

ORA-28031: maximum of 148 enabled roles exceeded

  1. Recently a full import was performed and all the roles from the source database are created on the target database by the same user. This is rather a consequence of the first cause presented above when roles are granted to the user who is creating them. However it is worth mentioning it separately since the roles were not explicitly created by the same user in the source database. Due to the way import tools are working the roles get created by the same user on the target DB.

  2. Recently an upgrade was performed. Before the upgrade the number of roles granted to a certain user was under 148 but in the new version new roles get created and eventually get granted to older roles. This way the total number of roles granted directly or recursively can exceed the limit.

References

MOS document id: 780749.1

Product Versions

product: Oracle Database - Enterprise Edition - min_version: 11.2.0.3 - max_version: 11.2.0.3; product: Oracle Database - Enterprise Edition - min_version: 8.1.7.4 - max_version: 11.1.0.7; product: Oracle Net Services - min_version: 19.1.0.0.0 - max_version: 19.1.0.0.0; Information in this article applies to GENERIC (All Platforms)

相关推荐
许彰午4 小时前
01-Oracle数据库简介与版本选择
数据库·oracle
菜鸟~noob2334 小时前
【电子战】第三季预告—波武器与电子系统强力毁伤
开发语言·数据库·matlab·电子战
Seraphina366 小时前
SQL注入(二)盲注
网络·数据库·经验分享·笔记·sql
盟接之桥7 小时前
AI助手:你的7×24小时智能管家——让异常预警无处不在
大数据·网络·数据库·人工智能·制造·ai编程
waoooqwe7 小时前
问卷样本真实吗
大数据·数据库·算法·数据分析
可乐ea8 小时前
Agent 评测换判据:用终态数据库状态判定任务是否完成
数据库·ui·oracle·mcp工具·agent评测·终态断言·智能体可靠性
l1t8 小时前
DeepSeek总结的一个不含数据的 DuckDB 数据库
服务器·数据库·duckdb
PaperData9 小时前
2007-2020年税收调查面板数据
数据库
程序员清风9 小时前
CSV、Excel 与数据库数据读取实践
数据库·oracle·excel
GEO实战经验分享9 小时前
GEO技术与工具全景:从监测仪表盘到Schema的实战指南
数据库