The v$sqlarea view displays the text of SQL statements in the shared SQL area, plus the number of users accessing the statements, disk blocks and memory blocks accessed while executing the statement, and other information.
In 10g, V$SQLSTATS takes the place of V$SQL when fetching statistics for SQL cursors, since it's
faster, more scalable, and has greater data retention.
For
9i and
10g set the 10046 event
- In init.ora,
set initialization parameters for trace file management:
STATISTICS_LEVEL = TYPICAL or ALL automatically collects dump files.
STATISTICS_LEVEL = BASIC means that dumps are not being collected.
TIMED_STATISTICS = TRUE
enables the collection of CPU and elapsed times and other stats into into dynamic session performance tables
This is since its default value is false.
USER_DUMP_DEST specifies the destination for the session trace file.
The default value is the default destination for system dumps, which contains a lot of other generated files.
This value can be modified with ALTER SYSTEM SET USER_DUMP_DEST= newdir.
MAX_DUMP_FILE_SIZE = 500 (operating system blocks) is the default.
"DUMP" refers to the SQL Trace facility text file, which is automatically truncated when full.
- Get into the DB server SQL prompt:
ls /etc/oratab
.oraenv
- Verify settings:
show parameters statistics
- Enable the session which Oracle will create trace files (for each process within the Oracle session):
DBMS_SESSION.SET_SQL_TRACE procedure or
ALTER SESSION SET SQL_TRACE = TRUE;
This creates a separate trace file for each process within the session.
To make trace file named for the process that created it,
include in programs a statement like SELECT program_name FROM DUAL.
The SQL Trace facility is automatically disabled for the session when the application disconnects from Oracle.
- Consolidate .prf files from several sessions using the
trcsess Utility.
trcsess output=output_report_file.prf
session=... clientid=.. service=... action=... module=...
trace_file1.trc
trace_file2.trc
- Format the trace file by running a command
such as:
tkprof input_trace_file.trc output_report_file.prf
INSERT=STOREA.SQL sys=NO
explain=username/password
sort='(prsela,exeela,fchela)'
call count cpu elapsed disk query current rows
---- ------- ------- --------- -------- -------- ------- ------
Parse 11 0.08 0.18 0 0 0 0
Execute 11 0.23 0.66 0 3 6 0
Fetch 35 6.70 6.83 100 12326 2 824
------------------------------------------------------------------
total 57 7.01 7.67 100 12329 8 826
Misses in library cache during parse: 0
Misses in library cache during execute: 1
Optimizer goal: CHOOSE
Parsing user id: 02 (USER02)
Statistics for RECURSIVE and NON-RECURSIVE queries are presented in separate reports.
Here are the field names:
Call | count (# times) | cpu seconds | elapsed clock seconds | # physical disk reads
| # consistent mode block reads in query | # current mode block reads
| # rows processed
| library cache misses |
Parse | PRSCNT | PRSCPU | PRSELA | PRSDSK
| PRSQRY | PRSCU | n/a | PRSMIS |
Execute | EXECNT | EXECPU | EXEELA | EXEDSK
| EXEQRY | EXECU | EXEROW | EXEMIS |
Fetch | FCHCNT | FCHCPU | FCHELA | FCHDSK
| FCHQRY | FCHCU | FCHROW | - |
- Interpret the output files:
"Parse" (parsing) is the verification of SQL code syntax and interpretive compilation into a form understandable by the Oracle Database engine.
The Optimizer attempts to automatically pick the fastest method of execution for an SQL code statement.
"Execute" is when SQL code statements are executed in various forms and by various routes, decided by the Optimizer.
"Fetch" is the return of results passed back to the calling process.
A large difference between "cpu" and "elasped" time may indicate
a) a lock contending with another transaction or
b) interference with a trigger or constraint.
The cache hit ratio is calculated from this number of physical reads vs. logical reads.
- "Consistent" reads are logical reads accessed in buffer cache for normal queries (SELECTs without for update clause).
- "Physical" reads may not really involve a hard disk drive access on disk arrays with their own cache.
Large "disk" values may indicate a full table scan from inefficient index schema.
- Collect times after running a query several times.
A time value of "0.01" is one hundredth of a second, or one millisecond - the smallest increment.
- Store the statistics in your own TKPROF_TABLE with a row of statistics for each traced SQL statement:
CREATE TABLE TKPROF_TABLE (
DATE_OF_INSERT DATE,
CURSOR_NUM NUMBER,
DEPTH NUMBER,
USER_ID NUMBER,
see above NUMBER,
CLOCK_TICKS NUMBER,
SQL_STATEMENT LONG);
- Conduct iterative tuning experiments ( Oracle Performance Improvement Methods)
by finding the "next biggest" bottleneck by comparing against baseline stats:
Consider automatic segment space management for tables and indexes with high INSERT/UPDATE/DELETE rates.
Consider automatic undo management to avoid contention of rollback segments.
Applications should use cursors with bind variables that open the cursor and execute it many times.
Dynamically generated SQL not using cursors create repeated parses of all SQL statements.
More on this at:
oracle-base