普通用戶在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>
此時應該檢查數據庫是否已經創建了角色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,如下所示。然後將該角色授予對應用戶即可。