1.生成跟踪文件
//会话级启用定时统计,TKPROF报告可以看到CPU时间,占用时间,可以看到瓶颈在哪里。
alter session set timed_statistics=true;
//alter session set events '10046 trace name context forever,level N'
//1启用标准SQL_TRACE工具(同SQL_TRACE=TRUE)
//4启用SQL_TRACE并捕捉跟踪文件中的绑定变量
//8启用SQL_TRACE并捕捉跟踪文件的等待事件
//12启用标准SQL_TRACE并捕捉绑定变量和等待事件
alter session set events '10046 trace name context forever,level 12';
select count(*) from big_table;
2.获取跟踪文件名
SQL> select rtrim(c.value,'/')||'/'||d.instance_name||'_ora_'||ltrim(to_char(a.spid))||'.trc'
2 from v$process a,v$session b,v$parameter c,v$instance d
3 where a.addr=b.paddr
4 and b.audsid= sys_context('userenv','sessionid')
5 and c.name='user_dump_dest';
RTRIM(C.VALUE,'/')||'/'||D.INSTANCE_NAME||'_ORA_'||LTRIM(TO_CHAR(A.SPID))||'.TRC
--------------------------------------------------------------------------------
C:\ORACLE\PRODUCT\10.2.0\ADMIN\ORADB\UDUMP/oradb_ora_1212.trc
3.创建TKPROF报告
SQL> exit
从 Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options 断
开
在当前目录创建tk.prf文件
C:\Users\Administrator>tkprof c:\oracle\product\10.2.0\admin\oradb\udump/oradb_ora_1212.trc tk.prf
TKPROF: Release 10.2.0.4.0 - Production on 星期日 9月 9 22:11:13 2012
Copyright (c) 1982, 2007, Oracle. All rights reserved.
C:\Users\Administrator>
4.查看TKPROF报告
********************************************************************************
select count(*) from big_table
call count cpu elapsed disk query current rows
------- ------ -------- ---------- ---------- ---------- ---------- ----------
Parse 2 0.00 0.00 0 4 3 0
Execute 1 0.00 0.13 0 0 0 0
Fetch 2 0.17 0.32 1370 21885 1 1
------- ------ -------- ---------- ---------- ---------- ---------- ----------
total 5 0.17 0.46 1370 21889 4 1
Misses in library cache during parse: 1
Optimizer mode: ALL_ROWS
Parsing user id: SYS
Rows Row Source Operation
------- ---------------------------------------------------
0 SORT AGGREGATE (cr=0 pr=0 pw=0 time=0 us)
0 TABLE ACCESS FULL BIG_TABLE (cr=0 pr=0 pw=0 time=0 us)
Elapsed times include waiting on following events:
Event waited on Times Max. Wait Total Waited
---------------------------------------- Waited ---------- ------------
SQL*Net break/reset to client 2 0.00 0.00
SQL*Net message to client 3 0.00 0.00
SQL*Net message from client 3 4.11 4.11
db file scattered read 87 0.01 0.13
********************************************************************************