ALTER SESSION SET sql_trace = false;
1.Get other session SID & SERIAL#
select sid,serial#,username from v$session where username = 'xxx';
SID SERIAL#
----- ----------
11 13442
2.Enable Sql Trace
alter system set timed_statistics = true;
execute dbms_system.set_sql_trace_in_session (<SID>, <SERIAL#>, true);
3.
…
Wait for a while,capture the sql
…
4.Stop the trace
execute dbms_system.set_sql_trace_in_session(<SID>, <SERIAL#>, false);
方法一:
1.Start SQL Trace on the complete database:
alter system set sql_trace = true scope=memory;
2.Stop SQL Trace on the complete database:
alter system set sql_trace = false scope=memory;
方法二:
参数文件(pfile/spfile)中指定: SQL_TRACE = true
查看user_dump_dest目录, 执行linux命令
ls *ptian01*
就会找到类似"SID_ora_nnnn_PTIAN01.trc"名字的trace文件。
或者执行下边这个Query,可以获取当前session Sql Trace的文件目录+名称
SELECT u_dump.value || '/' || db_name.value || '_ora_' || v$process.spid || nvl2(v$process.traceid, '_' || v$process.traceid, null ) || '.trc' "Trace File" from v$parameter u_dump cross join v$parameter db_name cross join v$process join v$session on v$process.addr = v$session.paddr where u_dump.name = 'user_dump_dest' and db_name.name = 'db_name' and v$session.audsid=sys_context('userenv','sessionid');output like:
/u01/oracle/mc3yd213/db/tech_st/11.1.0/admin/mc3yd213_bej301441/diag/rdbms/mc3yd213/mc3yd213/trace/mc3yd213_ora_9593.trc
TIMED_STATISTICS
This enables and disables the collection of timed statistics, such as CPU and elapsed times, by the SQL Trace facility, as well as the collection of various statistics in the dynamic performance tables. The default value of false disables timing. A value of true enables timing. Enabling timing causes extra timing calls for low-level operations. This is a dynamic parameter. It is also a session parameter.
MAX_DUMP_FILE_SIZE
When the SQL Trace facility is enabled at the instance level, every call to the server produces a text line in a file in the operating system's file format. The maximum size of these files (in operating system blocks) is limited by this initialization parameter. The default is 500. If you find that the trace output is truncated, then increase the value of this parameter before generating another trace file. This is a dynamic parameter. It is also a session parameter.
STATISTICS_LEVEL
controls all major statistics collections or advisories in the database.
BASIC: No advisories or statistics are collected.
TYPICAL: The following advisories or statistics are collected:
Buffer cache advisory
MTTR advisory
Shared Pool sizing advisory
Segment level statistics
PGA target advisory
Timed statistics
ALL: All of the preceding advisories or statistics are collected, plus the following:
Timed operating system statistics
Row source execution statistics
10046 Event Levels
10046 0 No statistics generated
10046 1 Standard trace output including parsing, executes and fetches plus more
10046 2 Same as Level 1
10046 4 Level 1 + Bind Variables
10046 8 Level 1 + Waits
10046 12 Level 1 + Bind Variables & Waits
Good Reference:http://www.jlcomp.demon.co.uk/faq/Tracing_Oracle_session.pdf
转载请注明出处:http://blog.csdn.net/pan_tian/article/details/8028297