set autotrace on 引发的问题

本文介绍了解决SQL*Plus自动跟踪功能时遇到的角色缺失及权限不足问题。通过创建PLUSTRACE角色并授予用户相应权限,最终解决了无法使用自动跟踪功能的问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

SQL> set autotrace on
SP2-0618: Cannot find the Session Identifier. Check PLUSTRACE role is enabled
SP2-0611: Error enabling STATISTICS report

SP2-0618: 无法找到会话标识符。启用检查 PLUSTRACE 角色
SP2-0611: 启用STATISTICS报告时出现错误

应该是该用户没有权限,以dba身份登录,对sl用户授权
[quote]SQL> grant plustrace to sl;
grant plustrace to sl
*
ERROR at line 1:
ORA-01919: role 'PLUSTRACE' does not exist 提示没有改角色。

SQL> select role from dba_roles where role='PLUSTRACE';
no rows selected[/quote]
数据库系统中没有该角色,但是我们可以通过执行 plustrce.sql($ORACLE_HOME/sqlplus/admin/plustrce.sql)脚本创建 plustrace
[quote]-- 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 "/ 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
[/quote]
执行完后 数据库中就存在该角色了。
[quote]
SQL> select role from dba_roles where role='PLUSTRACE';
ROLE
------------------------------
PLUSTRACE
[/quote]
可以通过查询session_roles表 查看当前用户所拥有的角色
[quote]
SESSION_ROLES describes the roles that are currently enabled to the user.
SQL> select * from session_roles;

ROLE
------------------------------
CONNECT
RESOURCE
PLUSTRACE

[/quote]

但是还是出现下面的问题
[quote][color=red]ERROR:
ORA-01039: insufficient privileges on underlying objects of the view
SP2-0612: Error generating AUTOTRACE EXPLAIN report
[/color][/quote]
解决方法:
[quote]
SQl>conn / as sysdba
SQL> grant select any dictionary to test;
[/quote]
[quote]advise you against adding this privilege to the users, it's very bad for security! You don't really need the traces for the queries on the SYS-owned objects.[/quote]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值