使用sqlplus时,连接到业务用户时,想查看某SQL的执行计划,报【SP2-0618: Cannot find the Session Identifier. Check PLUSTRACE role is enabled】和【SP2-0611: Error enabling STATISTICS report】,通过相关文档检索后得知原因是缺少plus trace ROLE的权限,解决思路:赋予用户plustrace 权限即可。
[oracle@db2 ~]$ sqlplus / as sysdba
SQL*Plus: Release 11.2.0.4.0 Production on Mon Mar 21 09:29:29 2016
Copyright (c) 1982, 2013, Oracle. All rights reserved.
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
SP2-0618: Cannot find the Session Identifier. Check PLUSTRACE role is enabled SP2-0611: Error enabling STATISTICS report 2.给用户赋予plustrace权限,报错【ORA-01919: role 'PLUSTRACE' does not exist】该角色不存在
SQL >grant plustrace to scott;
ORA-01919: role 'PLUSTRACE' does not exist 3.安装plustrce包,建立plustrace角色,执行$ORACLE_HOME/sqlplus/admin/plustrce.sql包
SQL >@?/sqlplus/admin/plustrce.sql
SQL >drop role plustrace;
ORA-01919: role 'PLUSTRACE' does not exist
SQL >create role plustrace;
SQL >grant select on v_$sesstat to plustrace;
SQL >grant select on v_$statname to plustrace;
SQL >grant select on v_$mystat to plustrace;
SQL >grant plustrace to dba with admin option;
SQL> grant plustrace to ptpcpuser;
SQL> select nvl(SUM(t.bean_count), 0)/100 from bean_record t WHERE t.invest_multip > 1 AND t.status = '2';
----------------------------------------------------------
Plan hash value: 3322369200
--------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time
--------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 9 | 77835 (1)| 00:15:35
| 1 | SORT AGGREGATE | | 1 | 9 | |
|* 2 | TABLE ACCESS FULL| BEAN_RECORD | 4591K| 39M| 77835 (1)| 00:15:35
--------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
2 - filter("T"."INVEST_MULTIP">1 AND "T"."STATUS"='2')
----------------------------------------------------------
549 bytes sent via SQL*Net to client
520 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
此问题有两个知识点,(1)是用户缺少set autotrace的权限,(2)是数据库缺少角色plustrace。这个问题对DBA来讲不是什么难事,但是还是要注意权限的管理与回收。继续学习喽,下回见。