代码改变世界

SQL*Plus环境下创建PLUSTRACE角色

  潇湘隐者  阅读(1816)  评论(0编辑  收藏  举报

普通用户在SQL*Plus中开启AUTOTRACE报告时,遇到SP2-0618: Cannot find the Session Identifier. Check PLUSTRACE role is enabled错误。如下所示:

SQL>

SQL> set autotrace on;

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

SP2-0611: Error enabling STATISTICS report

SQL>

clip_image001

此时应该检查数据库是否已经创建了角色PLUSTRACE,使用下面脚本检查角色PLUSTRACE是否存在。

SELECT * FROM DBA_ROLES WHERE ROLE='PLUSTRACE'

如果角色不存在,应该去$ORACLE_HOME/sqlplus/admin/目录下,你会找到plustrce.sql脚本文件。

[oracle@db-server ~]$ cd $ORACLE_HOME/sqlplus/admin/
[oracle@db-server admin]$ ls
glogin.sql  help  iplus  libisqlplus.def  libsqlplus.def  plustrce.sql  pupbld.sql
[oracle@db-server admin]$ more 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,如下所示。然后将该角色授予对应用户即可。

clip_image002

编辑推荐:
· 一个费力不讨好的项目,让我损失了近一半的绩效!
· .NET Core 托管堆内存泄露/CPU异常的常见思路
· PostgreSQL 和 SQL Server 在统计信息维护中的关键差异
· C++代码改造为UTF-8编码问题的总结
· DeepSeek 解答了困扰我五年的技术问题
阅读排行:
· 一个费力不讨好的项目,让我损失了近一半的绩效!
· 清华大学推出第四讲使用 DeepSeek + DeepResearch 让科研像聊天一样简单!
· 实操Deepseek接入个人知识库
· CSnakes vs Python.NET:高效嵌入与灵活互通的跨语言方案对比
· Plotly.NET 一个为 .NET 打造的强大开源交互式图表库
点击右上角即可分享
微信分享提示