10046event可以追蹤記錄orale有關sql執性語句情況。追蹤記錄檔案記錄在user_dump_dest指定的目錄下。
其中有四種level:
- 1:執行sql語句跟蹤;
- 4:綁定變數 ;
- 8:等待事件;
- 12:綁定變數和等待
開啟事件跟蹤:
- 針對所有session,在initsid.ora裡設定-開啟 或 alter system set:event='10046 trace name context forever,level n' [scope=spfile] --需要重啟oracle
- 針對所有session,在initsid.ora裡設定-關閉 或 alter system set:event='' [scope=spfile] --需要重啟oracle
- 針對當前session,開啟:alter session set events='10046 trace name context forever,level n' --立即生效
- 針對當前session,關閉:alter session set events='10046 trace name context off' --立即生效
- 針對其他session,如何跟蹤:
step1:確定要跟蹤的pid(oracle的processid) 或 spid(os的進程pid):
SELECT a.sid, a.serial#, b.spid, b.pid, a.username, a.osuser, a.machine
FROM v$session a, v$process b
WHERE a.username IS NOT NULL AND a.paddr=b.addr;
step2:以sysdba的身份登陸sqlplus
step3:初始化跟蹤,oradebug setpid pid_n | oradebug setospid spid_n
step4:開啟跟蹤,oradebug event 10046 trace name context forever,lever n
step5:關閉跟蹤,oradebug event 10046 trace name context off
其他:oradebu還可以設定追蹤檔案的fullpathname,oradebug tracefile_name filepec
6.使用dbms_system
Dbms_system.set_ev (
si binary_integer, -- SID
se binary_integer, -- Serial#
ev binary_integer, -- Event code or number to set.
le binary_integer, -- Usually level to trace
cm binary_integer -- When to trigger (NULL = context forever.)
To enable 10046 level 12 tracing for SID 22 with a serial# of 99 we would execute the set_ev procedure as shown here:
Exec dbms_system.set_ev(12,22,10046,12,’’);
To disable 10046 tracing enter the following:
Exec dbms_system.set_ev(12,22,10046,0,’’);