V$SESSION has three new columns now show the status of tracing:
sql_trace—Shows (TRUE/FALSE) if SQL tracing has been enabled in the session
sql_trace_waits—If session tracing is enabled, you can have the trace write wait information to the trace file; very useful in diagnosing performance issues.
sql_trace_binds—If the session uses bind variables, you can have the trace write the bind variable values to the trace file. This column shows TRUE/FALSE.
When tracing in the session is not turned on
select sid, serial#, sql_trace, sql_trace_waits, sql_trace_binds
from v$session where username = ‘USER1′
The output is:
SID SERIAL# SQL_TRAC SQL_T SQL_T
———- ———- ——– —– —–
196 60946 DISABLED FALSE FALSE
From the query we notice that tracing is not enabled in the session with SID 196 and Serial# 60946.
Now, enable tracing of wait events, but not of bind variables.
For that use the package dbms_monitor to enable tracing.
begin
dbms_monitor.session_trace_enable (
session_id => 196,
serial_num => 60946,
waits => true,
binds => false
);
end;
/
Now if you want to see the session information:
select sid, serial#, sql_trace, sql_trace_waits, sql_trace_binds
from v$session where username = ‘USER1′
The output is:
SID SERIAL# SQL_TRAC SQL_T SQL_T
———- ———- ——– —– —–
196 60946 ENABLED TRUE FALSE
Note:
View V$SESSION is populated only if the procedure session_trace_enable in the package dbms_monitor is used to enable tracing, not by alter session set sql_trace = true or setting the event 10046