今天在HR范例用户执行 set autot on的时候报:
SQL> set autotrace on
SP2-0618: Cannot find the Session Identifier. Check PLUSTRACE role is enabled
SP2-0611: Error enabling STATISTICS repor根据报错提示为HR用户赋予 plustrace角色:
SQL> conn / as sysdba
Connected.
SQL> grant plustrace to HR;
grant plustrace to HR
*
ERROR at line 1:
ORA-01919: role 'PLUSTRACE' does not exist可以看到该角色并不存在
查阅MOS发现该角色在建库时并不自动创建,需要使用sys用户运行脚本:
@$ORACLE_HOME/sqlplus/admin/plustrce.sqlSQL> drop role plustrace;
drop role plustrace
*
ERROR at line 1:
ORA-01919: role 'PLUSTRACE' does not exist
SQL> create role plustrace;
Role created.
SQL>
SQL> grant select on v_$sesstat to plustrace;
Grant succeeded.
SQL> grant select on v_$statname to plustrace;
Grant succeeded.
SQL> grant select on v_$mystat to plustrace;
Grant succeeded.
SQL> grant plustrace to dba with admin option;
Grant succeeded.
可以看出sql trace 其实以来上面几个动态视图:v_$sesstat、v_$statname、v_$mystat
运行脚本之后再为普通用户授权角色:
SQL> grant plustrace to HR;
Grant succeeded.
SQL> grant plustrace to OE;
Grant succeeded.
再次autot on:
(base) thekingofhenan:~ zhangmingxuan$ sqlplus HR/HR@orclpdb1
SQL*Plus: Release 19.0.0.0.0 - Production on Thu May 19 10:13:45 2022
Version 19.8.0.0.0
Copyright (c) 1982, 2020, Oracle. All rights reserved.
Last Successful login time: Thu May 19 2022 10:03:22 +08:00
Connected to:
Oracle Database 21c Enterprise Edition Release 21.0.0.0.0 - Production
Version 21.3.0.0.0
SQL> set autot on
SQL> ...............106 rows selected.
Execution Plan
----------------------------------------------------------
Plan hash value: 1445457117
-------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
-------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 106 | 7314 | 3 (0)| 00:00:01 |
|* 1 | TABLE ACCESS FULL| EMPLOYEES | 106 | 7314 | 3 (0)| 00:00:01 |
-------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
1 - filter("DEPARTMENT_ID" IS NOT NULL)
Statistics
----------------------------------------------------------
0 recursive calls
0 db block gets
13 consistent gets
0 physical reads
0 redo size
9005 bytes sent via SQL*Net to client
485 bytes received via SQL*Net from client
9 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
106 rows processed
「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。




