一.错误描述
SQL> set autotrace on;
SP2-0618: 无法找到会话标识符。启用检查 PLUSTRACE 角色
SP2-0611: 启用 STATISTICS 报告时出错
二.解决办法
2.1 登录到sys用户,找到$ORACLE_HOME/SQLPLUS/ADMIN/plustrce.sql,执行之
> sqlplus / as sysdba
> @$ORACLE_HOME/SQLPLUS/ADMIN/PLUSTRCE.SQL
2.2 我们打开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这个角色目的很明确了:
我们在SQL*PLUS上用SET AUTOTRACE ... STATISTICS的时候是通过plustrace这个角色来获取动态性能表信息的。当每一个用户要求使用该命令的时候会自动被DBA用户授予plustrace角色的权限。
参考:http://docs.oracle.com/cd/B10500_01/server.920/a96533/autotrac.htm