【最佳化】10046事件之生成跟蹤檔案
10046事件:
1)10046事件分類
10046 事件按照收集資訊內容,可以分成4個級別:
Level 1:跟蹤sql語句,包括解析、執行、提取、提交和回滾等;等同於SQL_TRACE 的功能
Level 4:在Level 1的基礎上增加收集繫結變數的資訊
Level 8:在Level 1 的基礎上增加等待事件的資訊
Level 12:等同於Level 4+Level 8, 即同時收集繫結變數資訊和等待事件資訊。
2)使用10046的前提條件
SYS@ORA11GR2>show parameter timed_statistics --是否收集與時間相關的統計資訊
NAME TYPE VALUE
------------------------------------ ----------- ------------------
timed_statistics boolean TRUE(預設)
SYS@ORA11GR2>show parameter statistics_level--此引數不允許為basic
NAME TYPE VALUE
------------------------------------ ----------- ------------------
statistics_level string TYPICAL(預設)
SYS@ORA11GR2>show parameter max_dump_file_size--注意此引數,如果trace檔案過於大的話,此引數要設定為unlimited(預設)
NAME TYPE VALUE
------------------------------------ ----------- ------------------
max_dump_file_size string unlimited(預設)
SYS@ORA11GR2>
3)非繫結變數實驗:
——建立測試表
SYS@ORA11GR2>create table t(id number(5) primary key,create_date date default sysdate not null);
Table created.
——開啟10046事件(收集一條或多條sql執行計劃的執行狀況)
SYS@ORA11GR2>alter session set events '10046 trace name context forever,level 12';
Session altered.
——對t表進行操作:
begin
for i in 21..40 loop
execute immediate'insert into t(id) values('||i||')';
end loop;
end;
/
PL/SQL procedure successfully completed.
——關閉10046事件
SYS@ORA11GR2>alter session set events '10046 trace name context off';
Session altered.
——查詢跟蹤檔案位置:
SELECT c.value || '/' || d.instance_name || '_ora_' || a.spid || '.trc' trace
FROM v$process a, v$session b, v$parameter c, v$instance d
WHERE a.addr = b.paddr
AND b.audsid = userenv('sessionid')
AND c.name = 'user_dump_dest';
TRACE
-------------------------------------------------------------------
/u01/app/oracle/diag/rdbms/ora11gr2/ORA11GR2/trace/ORA11GR2_ora_18140.trc
/u01/app/oracle/diag/rdbms/ora11gr2/ORA11GR2/trace/ORA11GR2_ora_10479.trc
/u01/app/oracle/diag/rdbms/ora11gr2/ORA11GR2/trace/ORA11GR2_ora_10495.trc
/u01/app/oracle/diag/rdbms/ora11gr2/ORA11GR2/trace/ORA11GR2_ora_14272.trc
其他的trace檔案要麼不存在,要麼不是當前生成的trace檔案;
SYS@ORA11GR2>
——利用tkprof工具格式化生成的trace檔案
[oracle@wang trace]$ tkprof ORA11GR2_ora_18140.trc 10046.txt
TKPROF: Release 11.2.0.4.0 - Development on Wed Oct 12 22:00:30 2016
Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.
驗證:
[oracle@wang trace]$ ls 10046.txt
10046.txt
[oracle@wang trace]$ pwd
/u01/app/oracle/diag/rdbms/ora11gr2/ORA11GR2/trace
——檢視:
[oracle@wang trace]$ cat 10046.txt
……省略……
*******************************************************************
SQL ID: 2fmndg2ajj1n7 Plan Hash: 0
insert into t(id)
values
(24)
call count cpu elapsed disk query current rows
------- ------ -------- ---------- ---------- ---------- ----------
Parse 1 0.00 0.00 0 0 0 0
Execute 1 0.00 0.00 0 1 3 1
Fetch 0 0.00 0.00 0 0 0 0
------- ------ -------- ---------- ---------- ---------- ----------
total 2 0.00 0.00 0 1 3 1
Misses in library cache during parse: 1
Optimizer mode: ALL_ROWS
Parsing user id: SYS (recursive depth: 1)
Number of plan statistics captured: 1
Rows (1st) Rows (avg) Rows (max) Row Source Operation
---------- ---------- ---------- ----------------------------------
0 0 0 LOAD TABLE CONVENTIONAL (cr=1 pr=0 pw=0 time=52 us)
*******************************************************************
省略其他插入值的執行計劃…………………………………………………………..
2)繫結變數實驗:
——開啟10046事件
SYS@ORA11GR2>alter session set events '10046 trace name context forever, level 12';
Session altered.
——進行操作生成trace檔案:
SYS@ORA11GR2>begin
2 for i in 1..20 loop
3 execute immediate 'insert into t(id,create_date) values(:1,:2)' using i,sysdate;
4 end loop;
5 end;
6 /
PL/SQL procedure successfully completed.
——檢視trace檔案位置:
SYS@ORA11GR2>SELECT c.value || '/' || d.instance_name || '_ora_' || a.spid || '.trc' trace
2 FROM v$process a, v$session b, v$parameter c, v$instance d
3 WHERE a.addr = b.paddr
4 AND b.audsid = userenv('sessionid')
5 AND c.name = 'user_dump_dest';
TRACE
-------------------------------------------------------------------
/u01/app/oracle/diag/rdbms/ora11gr2/ORA11GR2/trace/ORA11GR2_ora_18140.trc
/u01/app/oracle/diag/rdbms/ora11gr2/ORA11GR2/trace/ORA11GR2_ora_10479.trc
/u01/app/oracle/diag/rdbms/ora11gr2/ORA11GR2/trace/ORA11GR2_ora_10495.trc
——驗證:
[oracle@wang trace]$ ls /u01/app/oracle/diag/rdbms/ora11gr2/ORA11GR2/trace/ORA11GR2_ora_18140.trc
/u01/app/oracle/diag/rdbms/ora11gr2/ORA11GR2/trace/ORA11GR2_ora_18140.trc
[oracle@wang trace]$ ls /u01/app/oracle/diag/rdbms/ora11gr2/ORA11GR2/trace/ORA11GR2_ora_10479.trc
ls: /u01/app/oracle/diag/rdbms/ora11gr2/ORA11GR2/trace/ORA11GR2_ora_10479.trc: No such file or directory
[oracle@wang trace]$ ls /u01/app/oracle/diag/rdbms/ora11gr2/ORA11GR2/trace/ORA11GR2_ora_10495.trc
ls: /u01/app/oracle/diag/rdbms/ora11gr2/ORA11GR2/trace/ORA11GR2_ora_10495.trc: No such file or directory
——利用tkprof工具格式化生成的trace檔案
[oracle@wang trace]$ tkprof ORA11GR2_ora_18140.trc 10046.tkf
TKPROF: Release 11.2.0.4.0 - Development on Wed Oct 12 22:18:17 2016
Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.
——檢視:
[oracle@wang trace]$ ls 10046.t
10046.tkf 10046.txt
[oracle@wang trace]$
[oracle@wang trace]$ cat 10046.tkf
………………………………省略………………………………………………
*******************************************************************
begin
for i in 1..20 loop
execute immediate 'insert into t(id,create_date) values(:1,:2)' using i,sysdate;
end loop;
end;
call count cpu elapsed disk query current rows
------- ------ -------- ---------- ---------- ---------- ----------
Parse 1 0.00 0.00 0 0 0 0
Execute 1 0.00 0.00 0 0 0 1
Fetch 0 0.00 0.00 0 0 0 0
------- ------ -------- ---------- ---------- ---------- ----------
total 2 0.00 0.00 0 0 0 1
Misses in library cache during parse: 1
Optimizer mode: ALL_ROWS
Parsing user id: SYS
Elapsed times include waiting on following events:
Event waited on Times Max. Wait Total Waited
---------------------------------------- Waited ---------- ---
SQL*Net message to client 1 0.00 0.00
SQL*Net message from client 1 0.00 0.00
*******************************************************************
SQL ID: bdsmcbhvqt7by Plan Hash: 0
insert into t(id,create_date)
values
(:1,:2)
call count cpu elapsed disk query current rows
------- ------ -------- ---------- ---------- ---------- ----------
Parse 1 0.00 0.00 0 0 0 0
Execute 20 0.00 0.00 0 1 62 20
Fetch 0 0.00 0.00 0 0 0 0
------- ------ -------- ---------- ---------- ---------- ----------
total 21 0.00 0.00 0 1 62 20
Misses in library cache during parse: 1
Misses in library cache during execute: 1
Optimizer mode: ALL_ROWS
Parsing user id: SYS (recursive depth: 1)
Number of plan statistics captured: 1
Rows (1st) Rows (avg) Rows (max) Row Source Operation
---------- ---------- ---------- ----------------------------------
0 0 0 LOAD TABLE CONVENTIONAL (cr=1 pr=0 pw=0 time=162 us)
*******************************************************************
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/31397003/viewspace-2126466/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- ORACLE 10046 設定跟蹤事件後無跟蹤檔案Oracle事件
- 【最佳化】SQL_TRACE之生成跟蹤檔案SQL
- 【最佳化】DBMS_MONITOR包之生成跟蹤檔案
- [zt] oracle跟蹤檔案與跟蹤事件Oracle事件
- oracle跟蹤檔案與跟蹤事件(zt)Oracle事件
- oracle跟蹤檔案和跟蹤事件(zt)Oracle事件
- 10046事件跟蹤會話sql事件會話SQL
- 啟用跟蹤事件10046---06事件
- 跟蹤SQL - SQL Trace 及 10046 事件SQL事件
- 對使用dblink的10046事件跟蹤事件
- 10046 跟蹤的trace檔案相關解釋
- 使用10046事件跟蹤分析執行計劃事件
- 使用oracle的10046事件跟蹤SQL語句Oracle事件SQL
- 檔案-跟蹤檔案
- 使用10046事件 +10704事件對索引線上重建的跟蹤事件索引
- 怎樣收集10046跟蹤檔案來診斷效能問題
- Oracle跟蹤檔案Oracle
- 【10053 事件】10053事件的跟蹤檔案解析事件
- Oracle 10046跟蹤的使用Oracle
- 10046 跟蹤其他會話會話
- Oracle跟蹤檔案trace檔案Oracle
- SQL效能的度量 - 利用10046事件擴充套件SQL跟蹤SQL事件套件
- 解析listener跟蹤檔案
- git 忽略跟蹤檔案Git
- 尋找跟蹤檔案
- 控制檔案的跟蹤檔案全文
- oracle sql跟蹤 event 10046 - 轉OracleSQL
- 使用10046跟蹤sql語句SQL
- 透過ORADEBUG運用10046事件跟蹤SQL語句事件SQL
- Git跟蹤與提交檔案Git
- 獲取跟蹤檔案位置
- 獲取跟蹤檔案_eygle
- 跟蹤 sql 的trace檔案SQL
- tkprof: 分析ORACLE跟蹤檔案Oracle
- 【TRACE】Oracle跟蹤事件Oracle事件
- Oracle 跟蹤事件【轉】Oracle事件
- Oracle 跟蹤檔案和檔案轉儲(dump)Oracle
- .gitignore忽略跟蹤指定檔案Git