一:版本信息
操作系统版本 AIX 6109
数据库版本 11.2.0.3(PSU11)
二:错误描述
以普通用户使用set autotrace 命令时报如下错误:
SQL> set autotrace traceonly; SP2-0618: Cannot find the Session Identifier. Check PLUSTRACE role is enabled SP2-0611: Error enabling STATISTICS report
三:错误原因及解决方案
根据上面的错误提示“SP2-0618: Cannot find the Session Identifier. Check PLUSTRACE role is enabled”我们知道是因为PLUSTRACE角色没有授权给该用户导致的。
那么我们来看看PLUSTRACE 角色包含哪些权限
SQL> select * from dba_role_privs where granted_role='PLUSTRACE';
no rows selected
##数据库中根本没有PLUSTRACE角色。
那我们来看看PLUSTRACE角色的创建脚本是什么样的
查看$ORACLE_HOME/sqlplus/admin下的plustrce.sql发现如下内容
cat 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 role的创建脚本,我们知道有两种方式可以解决我们遇到的问题
1) 给需要使用set autotrace功能的用户赋予如下权限
grant select on v_$sesstat to test;
grant select on v_$statname to test;
grant select on v_$mystat to test;
2) 按照上面的plustrce.sql脚本创建PLUSTRACE角色,并把PLUSTRACE角色赋予相关用户
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;
grant plustrace to test;
相关链接
SET AUTOTRACE fails with SP2-0618 and SP2-0611 (Doc ID 1159115.1)