在oracle10g环境下:
1.查看sql执行计划:autotrace
>set autotrace on
>set autotrace off
默认情况是off
2.查看sql运行轨迹:sql_trace 和10046event
1)本session内:开启>alter session set sql_trace=true;
关闭>alter session set sql_trace=false;
默认情况是false;
2)其他用户session:
查询其他session> select sid,serial#,username from v$session where username is not null;
开启>exec dbms_system.set_sql_trace_in_session(sid,serial#,true);
关闭>exec dbms_system.set_sql_trace_in_sesson(sid,serial#,false);
10046event 是sql_trace的增强版。
1)本session内: >alter session set events '10046 trace name context forever,level *';
>alter session set events '10046 trace name context off';
2)其他用户session:
查询其他session> select sid,serial#,username from v$session where username is not null;
>exec dbms_system.set_ev(sid,serial#,10046,level,null);
>exec dbma_system.set_ev(sid,serial#,10046,0,null);
3. 获取跟踪文件:
select
d.value||'/'||lower(rtrim(i.instance, chr(0)))||'_ora_'||p.spid||'.trc' trace_file_name
from
( select p.spid
from sys.v$mystat m,sys.v$session s,sys.v$process p
where m.statistic# = 1 and s.sid = m.sid and p.addr = s.paddr) p,
( select t.instance from sys.v$thread t,sys.v$parameter v
where v.name = 'thread' and (v.value = 0 or t.thread# = to_number(v.value))) i,
( select value from sys.v$parameter where name = 'user_dump_dest') d
/
4.Tkprof工具格式化trc文件
>tkprof old.trc 1.txt