s..."/>
溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

SCOTT 用戶開啟autotrace 功能

發(fā)布時間:2020-07-23 09:47:11 來源:網(wǎng)絡(luò) 閱讀:278 作者:vast2006 欄目:關(guān)系型數(shù)據(jù)庫

想用SCOTT用戶做執(zhí)行計劃的實驗,發(fā)現(xiàn)無法使用;按理說任何可以使用sqlplus 的用戶都可以在session下啟用autotrace 功能,不過有的需要做下設(shè)置;



sys 用戶

SQL> select * from v$version;

BANNER
--------------------------------------------------------------------------------
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
PL/SQL Release 11.2.0.3.0 - Production
CORE    11.2.0.3.0      Production
TNS for Linux: Version 11.2.0.3.0 - Production
NLSRTL Version 11.2.0.3.0 - Production

SQL> select username,account_status from dba_users where username='SCOTT';

USERNAME                       ACCOUNT_STATUS
------------------------------ --------------------------------
SCOTT                          EXPIRED & LOCKED


SQL> alter user scott account  unlock identified by tiger;

User altered.


SQL>
SQL> select username,account_status from dba_users where username='SCOTT';

USERNAME                       ACCOUNT_STATUS
------------------------------ --------------------------------
SCOTT                          OPEN


SCOTT 用戶登錄


SQL> set autotrace on     //提示檢查PLUSTRACE角色是否開啟,

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


解決過程

1、以SYS用戶登錄,運行utlxplan.sql. 建立plan 表;

SQL> @?/rdbms/admin/utlxplan.sql           
Table created.

2、以sys用戶登錄,運行plustrce.sql,數(shù)據(jù)庫啟用autotrace功能的安裝腳本,主要是創(chuàng)建plustrace角色,并且授權(quán) ,擁有plustrace最主要的目的是為了訪問下面幾個VIEW :v_$sesstat;v_$statname;v_$mystat;

SQL> @?/sqlplus/admin/plustrce.sql
SQL>
SQL> drop role plustrace;
drop role plustrace
          *
ERROR at line 1:
ORA-01919: role 'PLUSTRACE' does not exist


SQL> create role plustrace;

Role created.

SQL>
SQL> grant select on v_$sesstat to plustrace;

Grant succeeded.

SQL> grant select on v_$statname to plustrace;

Grant succeeded.

SQL> grant select on v_$mystat to plustrace;

Grant succeeded.

SQL> grant plustrace to dba with admin option;

Grant succeeded.

SQL>
SQL> set echo off

SQL> grant plustrace to scott;

Grant succeeded.

3、以SCOTT 登錄

SQL> set autotrace on
SQL>
SQL> select * from dept;

    DEPTNO DNAME          LOC
---------- -------------- -------------
        10 ACCOUNTING     NEW YORK
        20 RESEARCH       DALLAS
        30 SALES          CHICAGO
        40 OPERATIONS     BOSTON


Execution Plan
----------------------------------------------------------
Plan hash value: 3383998547

--------------------------------------------------------------------------
| Id  | Operation         | Name | Rows  | Bytes | Cost (%CPU)| Time     |
--------------------------------------------------------------------------
|   0 | SELECT STATEMENT  |      |     4 |    80 |     3   (0)| 00:00:01 |
|   1 |  TABLE ACCESS FULL| DEPT |     4 |    80 |     3   (0)| 00:00:01 |
--------------------------------------------------------------------------


Statistics
----------------------------------------------------------
          2  recursive calls
          0  db block gets
         10  consistent gets
          4  physical reads
          0  redo size
        802  bytes sent via SQL*Net to client
        523  bytes received via SQL*Net from client
          2  SQL*Net roundtrips to/from client
          0  sorts (memory)
          0  sorts (disk)
          4  rows processed

SQL>




 設(shè)置Autotrace的命令

序號

命令

解釋

1

SET AUTOTRACE OFF

此為默認值,即關(guān)閉Autotrace

2

SET AUTOTRACE ON

產(chǎn)生結(jié)果集和解釋計劃并列出統(tǒng)計

3

SET AUTOTRACE ON EXPLAIN     

顯示結(jié)果集和解釋計劃不顯示統(tǒng)計

4

SET AUTOTRACE TRACEONLY 

顯示解釋計劃和統(tǒng)計,盡管執(zhí)行該語句但您將看不到結(jié)果集

5

SET AUTOTRACE TRACEONLY STATISTICS  

只顯示統(tǒng)計

PS:SET AUTOTRACE ON, set timing on, alter session set time_statistics=true;

Autotrace執(zhí)行計劃的各列的涵義

序號

列名

解釋

1

ID_PLUS_EXP                          

每一步驟的行號

2

PARENT_ID_PLUS_EXP        

每一步的Parent的級別號

3

PLAN_PLUS_EXP                   

實際的每步

4

OBJECT_NODE_PLUS_EXP

Dblink或并行查詢時才會用到

 Autotrace Statistics常用列解釋

序號

列名

解釋

1

db block gets       

從buffer cache中讀取的block的數(shù)量

2

consistent gets  

從buffer cache中讀取的undo數(shù)據(jù)的block的數(shù)量

3

physical reads   

從磁盤讀取的block的數(shù)量

4

redo size             

DML生成的redo的大小

5

sorts (memory)  

在內(nèi)存執(zhí)行的排序量

6

sorts (disk)         

在磁盤上執(zhí)行的排序量




向AI問一下細節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI