Thursday 14 February 2013

Working with trace files.

1. Add trigger to DB for the user you want to debug.

create or replace
TRIGGER scott.sqltrace
AFTER LOGON ON DATABASE
BEGIN
    --
    -- Only process specific user(s)
    --
    IF (user IN ('ALI')) THEN
       EXECUTE IMMEDIATE 'ALTER SESSION SET tracefile_identifier=''Ali''';
       EXECUTE IMMEDIATE 'ALTER SESSION SET max_dump_file_size = UNLIMITED';
        EXECUTE IMMEDIATE 'ALTER SESSION SET EVENTS ''10046 trace name context forever, level 12''';
    END IF;
END;
---

2. Grant Alter session to schema on wich trigger is added here scott

GRANT ALTER SESSION TO SCOTT;

3. Login to application and perform action to debug.

 i.e View records,Perform Deletion or updation.

4. Pick trace files from the trace folder and copy to any other folder . 
    (Get trace location from the following query)

Note:  Remember to disable trigger scott.sqltrace when you have finished tracing.

 Alter trigger scott.sqltrace disable;

Query to get trace file path

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');

5. Go to  cmd /dos prompt go to trace file folder  and use tkprof or tvdxstat  to generate readable format file.

                    Usually file with big size contains your queries.

     tkprof scott_ora_10728.trc SCOTT_ora_10728.tk
or


    tvdxtat -i scott_ora_10728.trc -o scott_ora_10728.html

Note: tvdxtat is batter utility to analyze trace file because it provide detail information such as bind variable values.

tvdxtat can be downloaded from the following link for free.

http://www.antognini.ch/top/downloadable-files

now open SCOTT_ora_10728.tk and find readable output.

No comments:

Post a Comment