sql_trace和tkprof的簡單應用

SQL_TRACE命令能使SQL的執行過程寫入到一個TRACE文件,這是性能診斷和調優過程中一種非常重要的工具也是比掌握的技能之一,下面通過一個小實驗學習下該工具。

SQL> alter session set tracefile_identifier=’test’;設置trace文件的標識,便於trace文件的定位

Session altered.

SQL> alter session set sql_trace=true;啓動當前session的sql_trace

Session altered.

SQL> select * from t where object_id=100;    該命令的執行過程已經寫入到trace文件

ID OWNER                          OBJECT_NAME

———- —————————— ——————————

SUBOBJECT_NAME                  OBJECT_ID DATA_OBJECT_ID OBJECT_TYPE

—————————— ———- ————– ——————-

CREATED   LAST_DDL_ TIMESTAMP           STATUS  T G S

——— ——— ——————- ——- – - -

1 SYS                            I_TYPED_VIEW1

100            100 INDEX

30-JUN-05 30-JUN-05 2005-06-30:19:10:18 VALID   N N N


SQL> alter session set sql_trace=false; 關閉sql_trace

Session altered.

生成的trace文件默認放在 $ORACLE_BASE/admin/SID/udump 目錄

進入udump目錄,找到與test相關關鍵詞的trace文件,利用tkprof工具轉化成易於閱讀的文本格式。

[oracle@prod udump]$ tkprof prod1_ora_4554_test.trc prod1_ora_4554_test.txt        轉換格式

TKPROF: Release 10.2.0.1.0 – Production on Fri Jul 13 12:49:04 2012

Copyright (c) 1982, 2005, Oracle.  All rights reserved.


[oracle@prod udump]$ cat prod1_ora_4554_test.txt   格式轉換成功,下面看到的就是上面執行的select語句的執行過程,格式很清爽,看着非常的舒服。


TKPROF: Release 10.2.0.1.0 – Production on Fri Jul 13 12:49:04 2012


Copyright (c) 1982, 2005, Oracle.  All rights reserved.


Trace file: prod1_ora_4554_test.trc

Sort options: default


********************************************************************************

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

********************************************************************************


alter session set sql_trace=true



call     count       cpu    elapsed       disk      query    current        rows

——- ——  ——– ———- ———- ———- ———-  ———-

Parse        0      0.00       0.00          0          0          0           0

Execute      1      0.00       0.00          0          0          0           0

Fetch        0      0.00       0.00          0          0          0           0

——- ——  ——– ———- ———- ———- ———-  ———-

total        1      0.00       0.00          0          0          0           0


Misses in library cache during parse: 0

Optimizer mode: ALL_ROWS

Parsing user id: 61

********************************************************************************


select *

from

t where object_id=100



call     count       cpu    elapsed       disk      query    current        rows

——- ——  ——– ———- ———- ———- ———-  ———-

Parse        1      0.00       0.00          0          0          0           0

Execute      1      0.00       0.00          0          0          0           0

Fetch        2      0.01       0.01          0        712          0           1

——- ——  ——– ———- ———- ———- ———-  ———-

total        4      0.01       0.01          0        712          0           1


Misses in library cache during parse: 1

Optimizer mode: ALL_ROWS

Parsing user id: 61


Rows     Row Source Operation

——-  —————————————————

1  TABLE ACCESS FULL T (cr=712 pr=0 pw=0 time=293 us)


********************************************************************************


alter session set sql_trace=false



call     count       cpu    elapsed       disk      query    current        rows

——- ——  ——– ———- ———- ———- ———-  ———-

Parse        1      0.00       0.00          0          0          0           0

Execute      1      0.00       0.00          0          0          0           0

Fetch        0      0.00       0.00          0          0          0           0

——- ——  ——– ———- ———- ———- ———-  ———-

total        2      0.00       0.00          0          0          0           0


Misses in library cache during parse: 1

Optimizer mode: ALL_ROWS

Parsing user id: 61




********************************************************************************


OVERALL TOTALS FOR ALL NON-RECURSIVE STATEMENTS


call     count       cpu    elapsed       disk      query    current        rows

——- ——  ——– ———- ———- ———- ———-  ———-

Parse        2      0.00       0.00          0          0          0           0

Execute      3      0.00       0.00          0          0          0           0

Fetch        2      0.01       0.01          0        712          0           1

——- ——  ——– ———- ———- ———- ———-  ———-

total        7      0.01       0.02          0        712          0           1


Misses in library cache during parse: 2



OVERALL TOTALS FOR ALL RECURSIVE STATEMENTS


call     count       cpu    elapsed       disk      query    current        rows

——- ——  ——– ———- ———- ———- ———-  ———-

Parse        0      0.00       0.00          0          0          0           0

Execute      0      0.00       0.00          0          0          0           0

Fetch        0      0.00       0.00          0          0          0           0

——- ——  ——– ———- ———- ———- ———-  ———-

total        0      0.00       0.00          0          0          0           0


Misses in library cache during parse: 0


3  user  SQL statements in session.

0  internal SQL statements in session.

3  SQL statements in session.

********************************************************************************

Trace file: prod1_ora_4554_test.trc

Trace file compatibility: 10.01.00

Sort options: default


1  session in tracefile.

3  user  SQL statements in trace file.

0  internal SQL statements in trace file.

3  SQL statements in trace file.

3  unique SQL statements in trace file.

41  lines in trace file.

54  elapsed seconds in trace file.


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章