Вы находитесь на странице: 1из 2

STEP 1: Configure the environment:

-------------------------------------------------------------

Enable Timed Statistics to collect certain vital statistics such as CPU execution
time, wait events and elapsed times.

SQL> alter system set timed_statistics = true;

System altered.

Check the USER DUMP destination directory using init.ora file (user_dump_dest
parameter) or by firing following SQL:

SQL> select value from v$parameter


where name = 'user_dump_dest';

VALUE
---------------------------------------------------
E:\oracle\admin\archana\udump

STEP 2: Turn the tracing ON:


------------------------------------------------

By default tracing is disabled due to the burden (5-10%) it plces on the database.
Enable tracing at session level:

SQL> alter session set sql_trace = true;

Session altered.

To get th file name of the trace file name for the currently connected session,
fire following query:

SQL>
select c.value || '\' || lower(d.value)
|| '_ora_' || to_char(a.spid, 'fm00000')
|| '.trc' "Trace File"
from v$process a, v$session b, v$parameter c, v$parameter d
where a.addr = b.paddr
and b.audsid = userenv('sessionid')
and c.name = 'user_dump_dest'
and d.name = 'db_name';

Output:
------------
Trace File
--------------------------------------------------------
E:\oracle\admin\archana\udump\archana_ora_04760.trc

Then fire some queres to check the statistics. we will fire following query:

select * from emp where ename = 'SCOTT';


select * from emp where empno = 7788;

STEP 3: Turn the tracing off:


-----------------------------------------------

SQL> alter session set sql_trace = false;

Session altered.

STEP 4: Locate trace file and execute tkprof:


---------------------------------------------------------------------------

Using earlier given query locate trace file and use tkprof from command line.

C:\Documents and Settings\archana_dhande>tkprof


e:\oracle\admin\archana\udump\archana_ora_4760.trc output.txt insert=tkprof.sql
record=Allsql.sql

TKPROF: Release 9.2.0.1.0 - Production on Wed Nov 12 11:57:27 2008

Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved.

Based on the command above, tkprof will process the file archana_ora_4760.trc and
format the results in the file output.txt. Two other files were also created
(tkprof.sql, allsql.sql).

STEP 5: Analyze tkprof output:


---------------------------------------------------
This is the most difficult step in the process. Each tkprof output file contains a
header, body, and summary section.

Header: The header simply displays the trace file name, definitions, and sort
options selected.

Body: The body contains the performance metrics for SQL statements.

Summary: The summary section contains an aggregate of performance statistics for


all SQL statements in the file.

Observe from the tkprof output above that the SQL statement performed a TABLE
ACCESS FULL, meaning a full-table scan. Full-table scans can degrade performance,
especially when accessing a small subset of the data in a table. In this case, the
query is selecting one row, yet all 100,000 rows in the table are scanned. This is
a perfect situation to add an index to improve the performance.

Вам также может понравиться