测试环境: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脚本,得到的结果如下:
执行完
$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
在进行执行计划测试的时候,遇到一个小问题。
在用普通用户执行下面这条命令的时候,普通用户名为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脚本,得到的结果如下:
点击(此处)折叠或打开
- SYS@ORCL>@$ORACLE_HOME/sqlplus/admin/plustrce.sql;
- SYS@ORCL>
- SYS@ORCL> drop role plustrace;
- drop role plustrace
- *
- ERROR at line 1:
- ORA-01919: role 'PLUSTRACE' does not exist
-
-
- SYS@ORCL> create role plustrace;
-
- Role created.
-
- SYS@ORCL>
- SYS@ORCL> grant select on v_$sesstat to plustrace;
-
- Grant succeeded.
-
- SYS@ORCL> grant select on v_$statname to plustrace;
-
- Grant succeeded.
-
- SYS@ORCL> grant select on v_$mystat to plustrace;
-
- Grant succeeded.
-
- SYS@ORCL> grant plustrace to dba with admin option;
-
- Grant succeeded.
-
- SYS@ORCL>
- SYS@ORCL> set echo off
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/