Tuesday, April 10, 2007

How To Trace Problem SQL

Trace Other's Session

exec sys.dbms_system.set_ev(130, 54378, 10046, 8, ''); #(sid=130 and serial#=54378)
exec sys.dbms_system.set_ev(130, 54378, 10046, 0, '');

LE - Level eg: 1 (SQL_TRACE), 4 (SQL_TRACE+BINDS), 8 (SQL_TRACE+WAITS), or 12(SQL_TRACE+BINDS+WAITS)


Trace Own Session

Set session parameter, if any


alter session set "_optim_peek_user_binds"=false;

Generate 10046 and 10053 traces for query

-- Set event 10046 and run the query.
alter session set tracefile_identifier = ee10046_literal;
alter session set events '10046 trace name context forever, level 12';
@sql
alter session set events '10046 trace name context off';
exit


-- Set event 10053 and run the query.
alter session set tracefile_identifier = ee10053_literal;
alter session set events '10053 trace name context forever, level 1';
@sql
alter session set events '10053 trace name context off';
exit

Generate tkprof output the 10046 trace files using following syntax (change the file name, username & password):
tkprof tracefile outputfile sys=no explain=query_username/password