Both SQL
Trace and TKPROF help to find the statistics of an SQL statement which could be
used for query optimization.
Start
Oracle SQLTRACE:
In Oracle, to
start an SQLTRACE for the current session, execute:
ALTER SESSION SET SQL_TRACE = TRUE;
Stop
Oracle SQLTRACE
In Oracle, to
stop SQL tracing for the current session, execute:
ALTER SESSION SET sql_trace = false;
Oracle SQLTRACE
provides generates the following statistics for each SQL statement:
·Count Number of
times OCI procedure was executed
·CPU CPU time
in seconds executing
·Elapsed Elapsed
time in seconds executing
·Disk Number
of physical reads of buffers from disk
·Query Number of
buffers gotten for consistent read
·Current Number of
buffers gotten in current mode (usually for update)
·Rows Number of
rows processed by the fetch or execute call
·Misses in library cache during parse
·Parsing user id
·Optimizer goal
When Oracle SQLTRACE facility
is enabled, all the statistics for all SQL statements executed after that are
placed into trace files. These trace files are not in readable format. Here comes the usage of TKPROF. TKPROF is used for formatting the
trace files to produce a more readable format. It stores the following
statistics of a Query:
·Resources
used by the SQL statement.
·No.
of times that the statement was called
·No of
records processed.
This utility is also used for monitoring
and tuning applications executing against the Oracle server.