日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

oracle 11g autotrace,ORACLE 使用AUTOTRACE功能

發布時間:2025/3/21 编程问答 54 豆豆
生活随笔 收集整理的這篇文章主要介紹了 oracle 11g autotrace,ORACLE 使用AUTOTRACE功能 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

ORACLE9i在使用autotrace之前,需要作一些初始的設置,

1.用sys用戶運行腳本ultxplan.sql

建立這個表的腳本是:(UNIX:$ORACLE_HOME/rdbms/admin, Windows:%ORACLE_HOME%\rdbms\admin)ultxplan.sql。

SQL> connect sys/sys@colm2 as sysdba;

SQL> @C:\oracle\ora92\rdbms\admin\utlxplan.sql;

SQL> create public synonym plan_table for plan_table;--建立同義詞

SQL> grant all on plan_table to public;--授權所有用戶

2.要在數據庫中建立一個角色plustrace,用sys用戶運行腳本plustrce.sql來創建這個角色,這個腳本在目錄(UNIX:$ORACLE_HOME/sqlplus/admin, Windows:%ORACLE_HOME%\sqlplus\admin)中;

SQL> @C:\oracle\ora92\sqlplus\admin\plustrce.sql;

3.然后將角色plustrace授予需要autotrace的用戶;

SQL>grant plustrace to public;

*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;

plustrce.sql腳本如下

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 select on v_$session to plustrace;

grant plustrace to dba with admin option;

4.經過以上步驟的設置,就可以在sql*plus中使用autotrace了,使用非常簡單,只要在執行語句之前,執行這樣一條命令:

SQL>set autotrace on

即可。

*autotrace功能只能在SQL*PLUS里使用

補充:

1.ORA-01039:視圖基本對象的權限不足的解決方法

ORA-01039:視圖基本對象的權限不足Current SQL statement for this session:

EXPLAIN PLAN SET STATEMENT_ID='PLUS561' FOR select table_name from user_tables

I think this is because the user doesn't have access to base tables for USER_TABLES view which belongs to SYS user.DBA role will do it, "SELECT ANY TABLE" (in 8i & 9i) , and "SELECT ANY DICTIONARY"(in 9i & 10g) system privileges should also do it. Try one of the following 3 ways and run your autotrace again:-1. 8i & 9i:-

grant select any table to USER123;

2. 9i and 10g:-

grant select any dictionary to USER123;

3. in 8i and 9i, you can also grant accees to the base tables explicitly ( or create a role to hold the grants ) :

grant select on OBJ$ to USER123;

grant select on USER$ to USER123;

grant select on SEG$ to USER123;

grant select on TS$ to USER123;

grant select on TAB$ to USER123;

2.在SQPPLUS中得到更新成功或者插入成功的記錄數

SQL>set feedback 1;

3.在SQPPLUS中得到語句總執行的時間

SQL> set timing on;

4.使用sys進行autotrace的話統計信息statistic都會為0

SQL> select count(*) from dba_objects;

COUNT(*)

----------

31820

Execution Plan

----------------------------------------------------------

0????? SELECT STATEMENT ptimizer=CHOOSE

1??? 0?? SORT (AGGREGATE)

2??? 1???? VIEW OF 'DBA_OBJECTS'

3??? 2?????? UNION-ALL

4??? 3???????? FILTER

5??? 4?????????? TABLE ACCESS (BY INDEX ROWID) OF 'OBJ$'

6??? 5???????????? NESTED LOOPS

7??? 6?????????????? TABLE ACCESS (FULL) OF 'USER$'

8??? 6?????????????? INDEX (RANGE SCAN) OF 'I_OBJ2' (UNIQUE)

9??? 4?????????? TABLE ACCESS (BY INDEX ROWID) OF 'IND$'

109???????????? INDEX (UNIQUE SCAN) OF 'I_IND1' (UNIQUE)

113???????? NESTED LOOPS

1211?????????? TABLE ACCESS (FULL) OF 'USER$'

1311?????????? INDEX (RANGE SCAN) OF 'I_LINK1' (NON-UNIQUE)

Statistics

----------------------------------------------------------

0?recursive calls

0?db block gets

0?consistent gets

0?physical reads

0?redo size

0?bytes sent via SQL*Net to client

0?bytes received via SQL*Net from client

0?SQL*Net roundtrips to/from client

0?sorts (memory)

0?sorts (disk)

1?rows processed

5.AUTOTRACE的幾個常用選項

(1).set autotrace on explain;--只顯示執行計劃

SQL> set autotrace on explain;

SQL>?select count(*) from dba_objects;

COUNT(*)

----------

31820

Execution Plan

----------------------------------------------------------

0????? SELECT STATEMENT ptimizer=CHOOSE

1??? 0?? SORT (AGGREGATE)

2??? 1???? VIEW OF 'DBA_OBJECTS'

3??? 2?????? UNION-ALL

4??? 3???????? FILTER

5??? 4?????????? TABLE ACCESS (BY INDEX ROWID) OF 'OBJ$'

6??? 5???????????? NESTED LOOPS

7??? 6?????????????? TABLE ACCESS (FULL) OF 'USER$'

8??? 6?????????????? INDEX (RANGE SCAN) OF 'I_OBJ2' (UNIQUE)

9??? 4?????????? TABLE ACCESS (BY INDEX ROWID) OF 'IND$'

109???????????? INDEX (UNIQUE SCAN) OF 'I_IND1' (UNIQUE)

113???????? NESTED LOOPS

1211?????????? TABLE ACCESS (FULL) OF 'USER$'

1311?????????? INDEX (RANGE SCAN) OF 'I_LINK1' (NON-UNIQUE)

(2).set autotrace on statistics;--只顯示統計信息

SQL> set autotrace on statistics;

SQL> select count(*) from dba_objects;

COUNT(*)

----------

31820

Statistics

----------------------------------------------------------

0?recursive calls

0?db block gets

25754?consistent gets

0?physical reads

0?redo size

383?bytes sent via SQL*Net to client

503?bytes received via SQL*Net from client

2?SQL*Net roundtrips to/from client

0?sorts (memory)

0?sorts (disk)

1?rows processed

(3).set autotrace traceonly;--同set autotrace on只是不顯示查詢輸出

SQL> set autotrace traceonly;

SQL> select count(*) from dba_objects;

Execution Plan

----------------------------------------------------------

0????? SELECT STATEMENT ptimizer=CHOOSE

1??? 0?? SORT (AGGREGATE)

2??? 1???? VIEW OF 'DBA_OBJECTS'

3??? 2?????? UNION-ALL

4??? 3???????? FILTER

5??? 4?????????? TABLE ACCESS (BY INDEX ROWID) OF 'OBJ$'

6??? 5???????????? NESTED LOOPS

7??? 6?????????????? TABLE ACCESS (FULL) OF 'USER$'

8??? 6?????????????? INDEX (RANGE SCAN) OF 'I_OBJ2' (UNIQUE)

9??? 4?????????? TABLE ACCESS (BY INDEX ROWID) OF 'IND$'

10??? 9???????????? INDEX (UNIQUE SCAN) OF 'I_IND1' (UNIQUE)

11??? 3???????? NESTED LOOPS

12?? 11?????????? TABLE ACCESS (FULL) OF 'USER$'

13?? 11?????????? INDEX (RANGE SCAN) OF 'I_LINK1' (NON-UNIQUE)

Statistics

----------------------------------------------------------

0?recursive calls

0?db block gets

25754?consistent gets

0?physical reads

0?redo size

383?bytes sent via SQL*Net to client

503?bytes received via SQL*Net from client

2?SQL*Net roundtrips to/from client

0?sorts (memory)

0?sorts (disk)

1?rows processed

(4).set autotrace traceonly explain;--比較實用的選項,只顯示執行計劃,但是與set autotrace on explain;相比不會執行語句,對于僅僅查看大表的Explain Plan非常管用。

SQL> set autotrace traceonly explain;

SQL> select * from dba_objects;

已用時間:?00: 00: 00.00

Execution Plan

----------------------------------------------------------

0????? SELECT STATEMENT ptimizer=CHOOSE

1??? 0?? VIEW OF 'DBA_OBJECTS'

2??? 1???? UNION-ALL

3??? 2?????? FILTER

4??? 3???????? TABLE ACCESS (BY INDEX ROWID) OF 'OBJ$'

5??? 4?????????? NESTED LOOPS

6??? 5?? ??????????TABLE ACCESS (FULL) OF 'USER$'

7??? 5???????????? INDEX (RANGE SCAN) OF 'I_OBJ2' (UNIQUE)

8??? 3???????? TABLE ACCESS (BY INDEX ROWID) OF 'IND$'

9??? 8?????????? INDEX (UNIQUE SCAN) OF 'I_IND1' (UNIQUE)

10??? 2?????? TABLE ACCESS (BY INDEX ROWID) OF 'LINK$'

11?? 10???????? NESTED LOOPS

12?? 11?????????? TABLE ACCESS (FULL) OF 'USER$'

13?? 11?????????? INDEX (RANGE SCAN) OF 'I_LINK1' (NON-UNIQUE)

6.Statistics參數的含義

recursive calls = basically sql performed on behalf of your sql.

So, if we had to PARSE the query for example, we might have

had to run some other queries to get data dictionary info.

that would be recursive calls.

db block gets = blocks gotten in "current" mode. That is,

blocks gotten as they exist right now. You'll see these

for full table scans (segment headers areread in current mode)

and modification statements (we modify the block as it

exists "right now")

consistent gets = blocks gotten in consistent read mode.

This is the mode we

read blocks in with a select for example. Also,

when you do a searchedUPDATE/DELETE, we read the blocks in

consistent read mode and then get the block in current mode

to actually do the modification. A select for update will do

this as well.

physical reads = self explanatory, physical IO

redo size = self explanatory -- amount of redo generated

sorts (memory)/(disk) -- sorts done.

總結

以上是生活随笔為你收集整理的oracle 11g autotrace,ORACLE 使用AUTOTRACE功能的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。