1. 程式人生 > >plustrace:set autotrace trace exp stat(SP2-0618、SP2-0611)

plustrace:set autotrace trace exp stat(SP2-0618、SP2-0611)

sta exp right str this root vertica rwx echo

1、報錯:當前用戶不能使用autotrace獲得執行計劃

技術分享
1 SQL> set autotrace trace exp stat;
2 
3 SP2-0618: Cannot find the Session Identifier. Check PLUSTRACE role is enabled
4 
5 SP2-0611: Error enabling STATISTICS report
View Code


2、切換為sys用戶,

技術分享
1 SQL> conn /as sysdba
2 
3 Connected.
View Code


3、授予用戶scott plustrace Role

,報錯plustrace角色不存在

技術分享
1 SQL> grant plustrace to scott;
2 
3 grant plustrace to scott
4 
5       *
6 
7 ERROR at line 1:
8 
9 ORA-01919: role PLUSTRACE does not exist
View Code


4、進入$ORACLE_HOME/sqlplus/admin/plustrce.sql目錄,通過運行如下SQL:plustrce.sql創建

[[email protected] admin]# pwd

/u01/app/oracle/product/11.2.4/dbhome_1/sqlplus/admin

[[email protected] admin]# ls -al

total 28

drwxr-xr-x 3 oracle dba 4096 Jun 4 22:23 .

drwxr-xr-x 7 oracle dba 4096 Jun 4 22:28 ..

-rw-r--r-- 1 oracle dba 368 Apr 10 2011 glogin.sql

drwxr-xr-x 2 oracle dba 4096 Jun 4 22:23 help

-rw-r--r-- 1 oracle dba 226 Jul 17 2013 libsqlplus.def

-rw-r--r-- 1 oracle dba 813 Mar 7 2006 plustrce.sql

-rw-r--r-- 1 oracle dba 2118 Feb 16 2003 pupbld.sql

1)查看$ORACLE_HOME/sqlplus/admin下的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

2)執行該sql創建plustrace角色。

技術分享
 1 SQL> @./plustrce.sql
 2 
 3 SQL>
 4 
 5 SQL> drop role plustrace;
 6 
 7 drop role plustrace
 8 
 9 *
10 
11 ERROR at line 1:
12 
13 ORA-01919: role PLUSTRACE does not exist
14 
15  
16 
17 SQL> create role plustrace;
18 
19 Role created.
20 
21 SQL>
22 
23 SQL> grant select on v_$sesstat to plustrace;
24 
25 Grant succeeded.
26 
27 SQL> grant select on v_$statname to plustrace;
28 
29 Grant succeeded.
30 
31 SQL> grant select on v_$mystat to plustrace;
32 
33 Grant succeeded.
34 
35 SQL> grant plustrace to dba with admin option;
36 
37 Grant succeeded.
38 
39 SQL>
40 
41 SQL> set echo off
42 
43 SQL>
44 
45 SQL> grant plustrace to rhys;
46 
47 Grant succeeded.
48 
49  
View Code


5、授予用戶 plustrace 角色

技術分享
1 SQL> grant plustrace to scott;
2 
3 
4 Grant succeeded.
5 
6 啟用 autotrace
7 
8 SQL> set autotrace on
View Code


至此問題解決

plustrace:set autotrace trace exp stat(SP2-0618、SP2-0611)