Collecting Oracle Extended Trace
-
Upload
sharad-shukla -
Category
Documents
-
view
222 -
download
0
Transcript of Collecting Oracle Extended Trace
-
8/7/2019 Collecting Oracle Extended Trace
1/3
-
8/7/2019 Collecting Oracle Extended Trace
2/3
This is easy if you know the sid and serial# of the session you want to trace. This canbe more difficult if MTS is used or commonly an application uses connection poolingwhere one connection can service many users.
Find the session:
set linesize 150column Name format a14column SID format 9999column PID format 99999column TERM format a15column OSUSER format a15column Program format a15column Stats format a10column Logon_time format a20select a.username Name,
a.sid SID,a.serial#, b.spid PID,
SUBSTR(A.TERMINAL,1,9) TERM,SUBSTR(A.OSUSER,1,9) OSUSER,
substr(a.program,1,10) Program,a.status Status,to_char(a.logon_time,'MM/DD/YYYY hh24:mi') Logon_time
from v$session a,
v$process bwhere a.paddr = b.addrand a.serial# '1'and a.status = 'ACTIVE'and a.username like upper('%&user%') -- if you want to filter by usernameorder by a.logon_time/
Once you have the SID and SERIAL# of the session you can use some Oracle suppliedpackages.
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_SYSTEMworks just fine. You will have to install this package and it is not available on allplatforms. 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:
-
8/7/2019 Collecting Oracle Extended Trace
3/3
In some applications it may be difficult to start tracing by changing code or finding asession because of connection pooling. Therefore, a logon trigger may help. Justenable it as long as needed for a short amount of time, as this could cause aperformance problem in heavily used systems. Note: The user that creates the triggermust be granted alter session explicitly, even if the user is system.
Create or replace the trigger set_tracing after logon on to the database.
beginif user like 'USERNAME%' thenexecute immediate 'alter session set timed_statistics=true';execute immediate 'alter session set max_dump_file_size=unlimited';execute immediate 'alter session set events ''10046 trace name context forever, level 8''';
end if;end;
Finding your trace files
All user session 10046 tracing will be located in user_dump_dest or
background_dump_dest for background traces. Oracles naming convention is platformdependant, but should have the spid in it returned from the session SQL above. Anexample on Solaris would be {ORACLE_SID}_ora_{spid}.trc (orcl_ora_1389.trc). Youcan also use the TRACEFILE_IDENTIFIER before you start the tracing, to help identifyyour trace files.
Future articles will include tracing parallel execution.