Collecting Oracle Extended Trace
Collecting Oracle Extended Trace
The most importing thing in collecting trace data is collecting properly scoped data. You
should know the application and user interaction. Collecting too little data can point you
in the wrong direction. Collecting data in the middle of a performance problem or long
wait will give you a partial trace file missing some important information. The best time
to collect is to turn tracing on, have a user start their process and turn tracing off after
the process has completed.
0 - no statistics
1 - basic statistics CURSOR, PARSE, EXEC, FETCH ERROR, SORT UMAP, ERROR,
UMAP, STATS and XCTEND. This is the same as setting sql_trace=true.
2 - same as level 1, do not know why they have this one.
4 - same as level 1 except adds BIND section
8 - same as level 1 except with wait events.
12 - combines all levels 4 and 8.
For timed wait event collecting you must have the parameter timed_statistics=true. You
can do this at the system level or session level. You should also set
max_dump_file_size=unlimited or you may receive the following in the trace file and
make it invalid:
WAIT #7: nam='db file sequential read' ela= 88 p1=6 p2=37500 p3=1
WAIT #7: nam='db fil
*** DUMP FILE SIZE IS LIMITED TO 10000000 BYTES ***
Once you have the SID and SERIAL# of the session you can use some Oracle supplied
packages.
DBMS_SYSTEM:
SQL> execute sys.dbms_system.set_boo_param_in_session(&&SID, &&SERIAL,'timed_statistics',true);
-- set timed statistics at user session level if not set at system level.
SQL> execute sys.dbms_system.set_in_param_in_session
(&&SID, &&SERIAL, 'max_dump_file_size',10000000);
set max dump file size if not set at system level.
SQL> execute sys.dbms_system.set_ev(&&SID, &&SERIAL, 10046, 8, ' ');
-- activate level 8 extended SQL tracing.
******* run all of your processing here *******
SQL> execute sys.dbms_system.set_ev(&&SID, &&SERIAL, 10046, 0, ' ');
-- disables extended SQL tracing.
DBMS_SUPPORT:
This package is preferred and fully supported by Oracle but the above DBMS_SYSTEM
works just fine. You will have to install this package and it is not available on all
platforms. To install run the dbmssupp.sql script as sysdba located in
$ORACLE_HOME/rdbms/admin directory.
SQL> execute sys.dbms_support.start_trace_in_session(&&SID, &&SERIAL, waits=>true, binds=>false);
-- equivalent to level 8 tracing, bind=>true would be equivalent to level 12 tracing.
******* run all of your processing here *******
SQL> execute sys.dbms_support.stop_trace_in_session(&&SID, &&SERIAL); -- end tracing.
Logon trigger:
In some applications it may be difficult to start tracing by changing code or finding a
session because of connection pooling. Therefore, a logon trigger may help. Just
enable it as long as needed for a short amount of time, as this could cause a
performance problem in heavily used systems. Note: The user that creates the trigger
must be granted alter session explicitly, even if the user is system.