1、對當前的session使用oradebug命令:sql
SQL> conn / as sysdbaapi
Connected.session
SQL> oradebug setmypidoracle
Statement processed.debug
或者對其餘session作跟蹤server
--鏈接到一個外部服務進程,且pid=v$process.pid進程
oradebug setorapid pid事件
--鏈接到一個外部服務進程,且spid=v$process.spidqt
oradebug setospid spidit
2、激活10046事件
SQL> oradebug event 10046 trace name context forever,level 12;
Statement processed.
3、執行目標sql語句
SQL> select empno,ename,dname from scott.emp,scott.dept where emp.deptno=dept.deptno;
EMPNO ENAME DNAME
---------- ---------- --------------
7782 CLARK ACCOUNTING
...省略相同內容
7654 MARTIN SALES
14 rows selected.
4、查看對應的trc文件及目錄
SQL> oradebug tracefile_name;
/u01/oracle/diag/rdbms/neal/neal/trace/neal_ora_18691.trc
5、關閉當前的10046跟蹤事件
SQL> oradebug event 10046 trace name context off;
Statement processed.
6、使用tkprof來格式化
[oracle@server ~]$ tkprof /u01/oracle/diag/rdbms/neal/neal/trace/neal_ora_18691.trc /tmp/neal_ora_18691.trc
7、查看獲得的neal_ora_18691.trc文件
SQL ID: 3yfu3wh150aqt Plan Hash: 844388907
select empno,ename,dname
from
scott.emp,scott.dept where emp.deptno=dept.deptno
call count cpu elapsed disk query current rows
------- ------ -------- ---------- ---------- ---------- ---------- ----------
Parse 1 0.03 0.04 0 161 0 0
Execute 1 0.00 0.00 0 0 0 0
Fetch 2 0.00 0.02 8 10 0 14
------- ------ -------- ---------- ---------- ---------- ---------- ----------
total 4 0.03 0.07 8 171 0 14
Misses in library cache during parse: 1
Optimizer mode: ALL_ROWS
Parsing user id: SYS
Number of plan statistics captured: 1
Rows (1st) Rows (avg) Rows (max) Row Source Operation
---------- ---------- ---------- ---------------------------------------------------
14 14 14 MERGE JOIN (cr=10 pr=8 pw=0 time=29081 us cost=6 size=364 card=14)
4 4 4 TABLE ACCESS BY INDEX ROWID DEPT (cr=4 pr=2 pw=0 time=19696 us cost=2 size=52card=4)
4 4 4 INDEX FULL SCAN PK_DEPT (cr=2 pr=1 pw=0 time=18734 us cost=1 size=0 card=4)(object id 87107)
14 14 14 SORT JOIN (cr=6 pr=6 pw=0 time=9416 us cost=4 size=182 card=14)
14 14 14 TABLE ACCESS FULL EMP (cr=6 pr=6 pw=0 time=9371 us cost=3 size=182 card=14)
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 10.81 20.69
Disk file operations I/O 1 0.00 0.00
db file sequential read 3 0.01 0.01
db file scattered read 1 0.00 0.00
********************************************************************************
OVERALL TOTALS FOR ALL NON-RECURSIVE STATEMENTS
call count cpu elapsed disk query current rows
------- ------ -------- ---------- ---------- ---------- ---------- ----------
Parse 1 0.03 0.04 0 161 0 0
Execute 1 0.00 0.00 0 0 0 0
Fetch 2 0.00 0.02 8 10 0 14
------- ------ -------- ---------- ---------- ---------- ---------- ----------
total 4 0.03 0.07 8 171 0 14
Misses in library cache during parse: 1
Elapsed times include waiting on following events:
Event waited on Times Max. Wait Total Waited
---------------------------------------- Waited ---------- ------------
SQL*Net message to client 6 0.00 0.00
SQL*Net message from client 6 34.85 80.64
Disk file operations I/O 1 0.00 0.00
db file sequential read 3 0.01 0.01
SQL*Net break/reset to client 2 0.00 0.00
db file scattered read 1 0.00 0.00
OVERALL TOTALS FOR ALL RECURSIVE STATEMENTS
call count cpu elapsed disk query current rows
------- ------ -------- ---------- ---------- ---------- ---------- ----------
Parse 13 0.01 0.01 0 0 0 0
Execute 82 0.03 0.08 0 0 0 0
Fetch 104 0.00 0.00 1 261 0 93
------- ------ -------- ---------- ---------- ---------- ---------- ----------
total 199 0.05 0.09 1 261 0 93
Misses in library cache during parse: 12
Misses in library cache during execute: 12
Elapsed times include waiting on following events:
Event waited on Times Max. Wait Total Waited
---------------------------------------- Waited ---------- ------------
Disk file operations I/O 1 0.00 0.00
db file sequential read 1 0.00 0.00
1 user SQL statements in session.
17 internal SQL statements in session.
18 SQL statements in session.
********************************************************************************
Trace file: /u01/oracle/diag/rdbms/neal/neal/trace/neal_ora_18691.trc
Trace file compatibility: 11.1.0.7
Sort options: default
1 session in tracefile.
1 user SQL statements in trace file.
17 internal SQL statements in trace file.
18 SQL statements in trace file.
17 unique SQL statements in trace file.
1323 lines in trace file.
10 elapsed seconds in trace file.