普通用户不能做AUTOTRACE,SP2-0618的错误

普通用户不能做AUTOTRACE,SP2-0618的错误
2011-8-24
Kevin Zou

在普通用户SQL TUNGING,在SQLPLUS中查看执行计划,想做AUTOTRACE时,常会遇到这样的问题:
SQL> set autotrace traceonly stat exp
SP2-0618: Cannot find the Session Identifier.  Check PLUSTRACE role is enabled
SP2-0611: Error enabling STATISTICS report

这是用SYSDBA帐号登录,检查PLUSTRACE 角色是否存在。

SQL> select * From dba_roles where role = 'PLUSTRACE' ; 

no rows selected

如果没有plustrace的角色,那需要执行ORACLE数据库提供的脚本。ORACLE版本不同,需要执行的脚本也不同:
在9I环境需要执行两个脚本:
@?/rdbms/admin/utlxplan.sql;
@?/sqlplus/admin/plustrce.sql;

在10G 中,只要执行一个语句可以了
@?/sqlplus/admin/plustrce.sql;
创建好plustrace的角色后,需要把角色赋予给PUBLIC。这样避免每个用户单独授权。
grant plustrace to public;

下面是实例显示:
SQL> conn /as sysdba
Connected.
SQL> @?/sqlplus/admin/plustrce.sql
SQL> 
SQL> drop role plustrace;
drop role plustrace
          *
ERROR at line 1:
ORA-01919: role 'PLUSTRACE' does not exist


SQL> create role plustrace;

Role created.

SQL> 
SQL> grant select on v_$sesstat to plustrace;

Grant succeeded.

SQL> grant select on v_$statname to plustrace;

Grant succeeded.

SQL> grant select on v_$mystat to plustrace;

Grant succeeded.

SQL> grant plustrace to dba with admin option;

Grant succeeded.

SQL> 
SQL> set echo off
SQL> grant plustrace to public;

Grant succeeded.

SQL> conn scott/tiger;
Connected.
SQL> set autotrace traceonly stat exp
到此,普遍用户可以正常的做AUTOTRACE。
-END-

请使用浏览器的分享功能分享到微信等