Oracle - SQL_TRACE

> Database > Oracle Database

2 - Steps

  • Set a trace identifier:
ALTER session SET tracefile_identifier = 'myIdentifier';

The trace file identifier is added to the name of the trace files.

  • Set Trace on:
ALTER session SET sql_trace = TRUE;
  • Perform SQL Actions
  • Set off
ALTER session SET sql_trace = FALSE;
  • Where are the trace files?
show parameter user_dump_dest
grep "A little bit of my statement" *.trc
  • Formatting of the trace file with tkprof.
tkprof oracl_ora.....trc

3 - Connection Pool

With a typical connection pool, a database session (the level at which we generally trace) is shared across multiple unrelated end-user sessions. Without a connection pool, the application would own a database connection, the level at which Oracle is built to “trace” at from start to finish.

With a connection pool, that one connection is shared by perhaps every end-user session in the system. We end up with a trace file that hase not only the trace information we are interested in, but the trace information from any-end user session that used the connection. The resulting trace file would be intermingled with my SQL, and with their SQL, and with everyone's SQL.

With a connection pool :

  • we must have the ability to turn on tracing for a specific user of for a specific module
  • when the connection pool grab a connection, it should issue alter session set sql_trace = true;
  • prior to returning the connection to the pool, it should issue set sql_trace = false;

4 - Reference