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

简介: 测试环境:OEL6.5+Oracle 11g R2在进行执行计划测试的时候,遇到一个小问题。在用普通用户执行下面这条命令的时候,普通用户名为hhu,已经赋予了create session和resource权限。
+关注继续查看
测试环境: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


相关文章
解决Only void and foreign elements can be self closed “ xxxx-xxxx“报错
解决Only void and foreign elements can be self closed “ xxxx-xxxx“报错
解决Only void and foreign elements can be self closed “ xxxx-xxxx“报错
|
关系型数据库 MySQL Java
Server returns invalid timezone. Go to 'Advanced' tab and set 'serverTimezone' property manually
Server returns invalid timezone. Go to 'Advanced' tab and set 'serverTimezone' property manually
3092 0
Server returns invalid timezone. Go to 'Advanced' tab and set 'serverTimezone' property manually
test of duplicate control id
Created by Jerry Wang, last modified on Aug 21, 2015
test of duplicate control id
test of ui5 duplicate control id
Created by Jerry Wang, last modified on Aug 21, 2015
test of ui5 duplicate control id
|
SQL 数据库 数据库管理
Replication-Replication Distribution Subsystem: agent xxxxxx failed. Column names in each table must be unique
原文:Replication-Replication Distribution Subsystem: agent xxxxxx failed. Column names in each table must be unique   最近遇到一个关于发布订阅(Replication)的奇葩问题,特此记录一下这个案例。
985 0
|
安全
Error Code: 1175. You are using safe update mode and you tried to update a t
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/inforstack/article/details/79677217 在安全模式下,只能根据主键来做修改,所以使用非主键修改,那么将要解除安全模式,然后再执行操作。
1584 0
|
数据安全/隐私保护
Give root password for maintenance(or type control -D to continue)
2017-09-30 18:12:08 1:错误如图,本来开机准备用一下虚拟机,就出现一个这,为啥记录一下呢,因为网上好多不是很靠谱。 原因可能是之前关闭虚拟机的时候不小心出现异常了: 2:解决办法:   个人根据自己的磁盘分区情况,进行修复即可; 解决方法,在鼠标停留的地方输入...
1740 0