10046 trace 产生方法

 Generate 10046 SQL Trace  (Doc ID 2978727.1)   

 
Its preferred to flush the cursor from the shared pool before start the tracing.

Using The DBMS_SHARED_POOL Package (Doc ID 457309.1)
For example:

select address, hash_value from v$SQLAREA where sql_id='';
exec dbms_shared_pool.purge ('

,','C');
Then use one of the below methods:

A. Use Alter session_trace_enable command:

Alter session set tracefile_identifier = 'xyz';
exec dbms_session.session_trace_enable(waits => true,binds => false);

-- Run the SQL
select * from dual;
exec dbms_session.session_trace_disable;


B. Using dbms_system

select username, status, sid, serial# from v$session where username ='&username' order by 1;
In below example, sid =1084 , serial# = 18003
exec dbms_system.set_sql_trace_in_session(1084 ,18003 ,true);
exec dbms_system.set_sql_trace_in_session(1084 ,18003 ,FALSE);

C. Using oradebug
*. Identify the shadow process ospid:

SELECT p.spid,p.addr,p.pid,s.sid,SUBSTR(s.username,1,15) "USERNAME",SUBSTR(s.program,1,15) "PROGRAM"
  FROM v$process p,v$session s
  WHERE s.paddr=p.addr
  AND addr in (SELECT paddr FROM v$session WHERE UPPER(program) LIKE '%%');
Verify the session is running at OS level

ps -ef | grep
*. In sqlplus, use oradebug to attach to this (O)SPID, set trace file size to unlimited and turn on Event 10046 at level 12

oradebug setospid xxx ----------- (xxx = ospid)
oradebug unlimited
oradebug Event 10046 trace name context forever, level 12
*. Start the the process you want to trace

*. When the process ended, disable the trace -- this after collecting the steps below

 oradebug Event 10046 trace name context off
D. Using dbms_monitor:

In below example, sid =1084 , serial# = 18003
exec dbms_monitor.session_trace_enable(session_id=> 1084 ,serial_num=>18003 ,binds=>true,waits=>true);
--Run the SQL
exec dbms_monitor.session_trace_disable(session_id=>1084,serial_num=>18003);
E. Using Alter session set events:

show parameter diagnostic_dest

alter session set tracefile_identifier='10046';

alter session set timed_statistics = true;
alter session set statistics_level=all;
alter session set max_dump_file_size = unlimited;

alter session set events '10046 trace name context forever,level 12';

-- Execute the queries or operations to be traced here --
-- Once the command, make sure to close the cursor using the below simple query
select * from dual;
--To get the trace file name, run the below command:
SELECT value FROM v$diag_info WHERE NAME='Default Trace File';
exit;
 F. To trace a specific SQL than runs from application and you can not run it from sqlplus:

alter system set timed_statistics=true;
alter system set statistics_level=all;
alter system set max_dump_file_size=unlimited;
alter system set events 'sql_trace[sql: SQLID] level=12';  -- replace the SQLID here

--Make sure the SQL has executed, then you need to disable the tracing

alter system set events 'sql_trace[sql: SQLID] off'; -- replace the SQLID here
alter system set statistics_level=typical;

 

你可能感兴趣的:(数据库,sql)