SP2-0618: Cannot find the Session Identifier. Check PLUSTRACE role is enabled

测试环境:OEL6.5+Oracle 11g R2

在进行执行计划测试的时候,遇到一个小问题。

在用普通用户执行下面这条命令的时候,普通用户名为hhu,已经赋予了create session和resource权限。在执行set autotrace on的时候,出现了如下错误:
SYS@ORCL> create user hhu identified by hhu;
User created.
SYS@ORCL> grant create session,resource to hhu;
Grant succeeded.
SYS@ORCL> conn hhu/hhu
Connected.
HHU@ORCL> create table t as select * from all_objects;
Table created.
HHU@ORCL> create index idx_object_id on t(object_id);
Index created.
HHU@ORCL> set autotrace on 
SP2-0618: Cannot find the Session Identifier.  Check PLUSTRACE role is enabled
SP2-0611: Error enabling STATISTICS report

第一次遇到这样的错误(可见还是菜鸟),目前还没财力购买一个mos帐号,于是乎去google了一下(官方文档应该也有解释,但是第一次遇到这样的问题,效率上不行),得到如下解释:
要执行autotrace命令用户必须要拥有PLUSTRACE角色,而这个角色默认赋予给用户的。使用sys用户执行$ORACLE_HOME/sqlplus/admin/plustrce.sql可以创建PLUSTRACE角色。
plustrce.sql这个脚本会创建PLUSTRACE角色并赋予查询v$sesstat,v$statnme以及v$mystat的权限。PLUSTRACE被以with admin option方式授权给DBA角色。
对于9i和更早期的数据库版本,可能还需要执行$ORACLE_HOME/rdbms/admin/utlxplan.sql脚本来创建plan table。而在10g以及更高的版本中,PLAN_TBALE是预先存在的。
也就是说,错误原因是我所使用的普通用户缺少一个能执行autotrace命令的相关角色,那么我只需要创建好这个角色即可,而创建这个角色只需要运行
$ORACLE_HOME/sqlplus/admin/plustrce.sql即可。


执行plustrce.sql脚本,得到的结果如下:

点击(此处)折叠或打开

  1. SYS@ORCL>@$ORACLE_HOME/sqlplus/admin/plustrce.sql;
  2. SYS@ORCL> 
  3. SYS@ORCL> drop role plustrace;
  4. drop role plustrace
  5.           *
  6. ERROR at line 1:
  7. ORA-01919: role 'PLUSTRACE' does not exist


  8. SYS@ORCL> create role plustrace;

  9. Role created.

  10. SYS@ORCL> 
  11. SYS@ORCL> grant select on v_$sesstat to plustrace;

  12. Grant succeeded.

  13. SYS@ORCL> grant select on v_$statname to plustrace;

  14. Grant succeeded.

  15. SYS@ORCL> grant select on v_$mystat to plustrace;

  16. Grant succeeded.

  17. SYS@ORCL> grant plustrace to dba with admin option;

  18. Grant succeeded.

  19. SYS@ORCL> 
  20. SYS@ORCL> set echo off
执行完 $ORACLE_HOME/sqlplus/admin/plustrce.sql这个脚本后,我们需要将PLUSTRACE角色赋予给hhu用户。
HHU@ORCL> conn / as sysdba
Connected.
SYS@ORCL> grant plustrace to hhu;
Grant succeeded.
SYS@ORCL> conn hhu/hhu
Connected.
HHU@ORCL> set autotrace on
HHU@ORCL> set linesize 1000
HHU@ORCL> 

下面是 $ORACLE_HOME/sqlplus/admin/plustrce.sql这个脚本的完整内容(实际上看上面这个脚本的执行过程也能分析出来):
[oracle@hhu ~]$ cat $ORACLE_HOME/sqlplus/admin/plustrce.sql
--
-- Copyright (c) Oracle Corporation 1995, 2002.  All Rights Reserved.
--
-- NAME
--   plustrce.sql
--
-- DESCRIPTION
--   Creates a role with access to Dynamic Performance Tables
--   for the SQL*Plus SET AUTOTRACE ... STATISTICS command.
--   After this script has been run, each user requiring access to
--   the AUTOTRACE feature should be granted the PLUSTRACE role by
--   the DBA.
--
-- USAGE
--   sqlplus "sys/knl_test7 as sysdba" @plustrce
--
--   Catalog.sql must have been run before this file is run.
--   This file must be run while connected to a DBA schema.


set echo on


drop role plustrace;
create role plustrace;


grant select on v_$sesstat to plustrace;
grant select on v_$statname to plustrace;
grant select on v_$mystat to plustrace;
grant plustrace to dba with admin option;


set echo off

可以发现,其实就是几条简单的创建角色并赋予相关权限的命令的组合,如果知道整个脚本内容,PLUSTRACE这个角色名是可以任意取的;在最后的命令中使用with admin option,说明该角色可被级联授予。


@huan


来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/29067253/viewspace-1984654/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/29067253/viewspace-1984654/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值