Example of how to trace a session and use tkprof
Enable trace for a user session:SQLPLUS> exec sys.dbms_system.set_sql_trace_in_session(SID, SERIAL, true); Use tkprof to analyze the trace file: tkprof [TRACE FILE] [OUTPUT FILE] explain=/ sort=prsela,exeela,fchela table=ops\$oracle.plan_table
identify trace file SELECT s.sid, s.serial#, pa.value || '/' || LOWER(SYS_CONTEXT('userenv','instance_name')) || '_ora_' || p.spid || '.trc' AS trace_file FROM v$session s, v$process p, v$parameter pa WHERE pa.name = 'user_dump_dest' AND s.paddr = p.addr AND s.audsid = SYS_CONTEXT('USERENV', 'SESSIONID');
logon trigger sample
CREATE OR REPLACE TRIGGER db_logon AFTER LOGON ON DATABASE declare my_exception exception; begin execute immediate 'begin; end;'; if user=' ' then execute immediate 'ALTER SESSION SET EVENTS ''10046 TRACE NAME CONTEXT FOREVER, LEVEL 12'''; --raise my_exception; end if; exception when my_exception then RAISE_APPLICATION_ERROR(-20001,'!!! ERROR'); when OTHERS then null; end;
Sql trace = true is equal to tracing for event 10046 at level 1Levels
SQL> alter system set events='10046 trace name context forever, level 1';
SQL> alter system set events='10046 trace name context off' ;
Level 4 is level 1 + bind variables (debugging)
SQL> alter system set events='10046 trace name context forever, level 4' ;
SQL> alter system set events='10046 trace name context off' ;
Level 8 is level 1 + wait info (performance tuning)
SQL> alter system set events='10046 trace name context forever, level 8' ;
Level 12 is level 1 + bind variables & wait info (debugging + performance tuning)
SQL> alter system set events='10046 trace name context forever, level 12' ;
In order to stop the 10046 session trace use this one
SQL> alter system set events='10046 trace name context off' ;
No comments:
Post a Comment