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,’’);