前一篇文章介绍了如何安装trca,接下来介绍
如何使用trca:必须进入 trca/run 目录里面 或者把 /home/oracle/software/trca/run 放到SQL_PATH环境变量里面:
使用trcanlzr.sql的时候可以直接跟trace 文件名字,该工具默认会到user_dump_dest 里面去找(对于10g以前的,会到bdump_dest 里面去找跟踪文件)
sys@RAC> show parameter user_dump_dest
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
user_dump_dest string /opt/rac/oracle/diag/rdbms/rac
/rac1/trace
oracle@rac1:/home/oracle/software/trca/run>sqlplus "/as sysdba"
SQL*Plus: Release 11.2.0.1.0 Production on Sat Oct 8 19:57:15 2011
sys@RAC> @trcanlzr.sql rac1_ora_17428.trc
Parameter 1:
Trace Filename or control_file.txt (required)
Value passed to trcanlzr.sql:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
TRACE_FILENAME: rac1_ora_17428.trc
Analyzing rac1_ora_17428.trc
To monitor progress, login as TRCANLZR into another session and execute:
SQL> SELECT * FROM trca$_log_v;
... analyzing trace(s) ...
Trace Analyzer completed.
Review first trcanlzr_error.log file for possible fatal errors.
Review next trca_e85484.log for parsing messages and totals.
Copying now generated files into local directory
TKPROF: Release 11.2.0.1.0 - Development on Sat Oct 8 19:57:34 2011
Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.
adding: trca_e85484.html (deflated 90%) 执行分析脚本以后,会产生五个文件,并打包成.zip文件
adding: trca_e85484.log (deflated 83%)
adding: trca_e85484.tkprof (deflated 85%)
adding: trca_e85484.txt (deflated 87%)
adding: trcanlzr_error.log (deflated 81%)
test of trca_e85484.zip OK
deleting: trcanlzr_error.log
Archive: trca_e85484.zip
Length Date Time Name
-------- ---- ---- ----
215465 10-08-11 19:57 trca_e85484.html
15721 10-08-11 19:57 trca_e85484.log
27117 10-08-11 19:57 trca_e85484.tkprof
115329 10-08-11 19:57 trca_e85484.txt
-------- -------
373632 4 files
File trca_e85484.zip has been created
TRCANLZR completed.
SQL>EXIT
oracle@rac1:/home/oracle/software/trca/run>ls
trca_e85484.zip trcanlzr.sql
oracle@rac1:/home/oracle/software/trca/run>unzip trca_e85484.zip
Archive: trca_e85484.zip
inflating: trca_e85484.html
inflating: trca_e85484.log
inflating: trca_e85484.tkprof
inflating: trca_e85484.txt
oracle@rac1:/home/oracle/software/trca/run>ls
trca_e85484.html trca_e85484.log trca_e85484.tkprof trca_e85484.txt trca_e85484.zip trcanlzr.sql
trca_e85484.html --可以以网页形式查看统计信息
trca_e85484.log --分析过程的日志
trca_e85484.tkprof --和常规的tkprof 产生的文件一样:记录了所有sql的执行计划,Parse,Execute,Fetch 。
trca_e85484.txt --以文本形式看出统计信息,和html的内容一样,只是形式是文本的方式。
相对于tkprof的优势:
1. 跟踪文件分析器能够显示出确切的绑定变量的值,dba再也不用考虑sql运行时,变量的值具体是什么!
显示的sql语句如下
DELETE FROM HISTORY where ALERT_TIME
Trace Analyzer 将会显示如下形式:
0:"2/4/2003 15:57:35" 1:1
就相当于:
DELETE FROM HISTORY where ALERT_TIME
2. Trace Analyzer 提供热块,优化器收集索引和表的统计信息和其他的信息,而这些是tkprof所不能提供的。
下面的输出展示了sql语句及其执行计划和相关对象的统计信息。
DELETE FROM SCOTT.EMPLOYEE
call count cpu elapsed disk query current rows misses
------- ------- ------- -------- -------- --------- --------- ------------ ---------
Parse 1 0.00 0.00 0 0 0 0 0
Execute 3 0.05 0.52 0 27 224 216 0
------- -------- -------- -------- -------- --------- --------- ----------- --------
total 4 0.05 0.52 0 27 224 216 0
Explain Plan
---------------------------------------------------------------
...3 DELETE STATEMENT
...2 .DELETE OF 'SCOTT.EMPLOYEE
...1 ..TABLE ACCESS (FULL) OF ‘SCOTT.EMPLOYEE'
OWNER.TABLE_NAME
...owner.index_name num rows blocks sample last analyzed date
------------------------------------ ---------- ---------- ---------- -------------------
SCOTT.EMPLOYEE..........................
The output above indicates that the EMPLOYEE table does not have statistics.
3.Trace Analyzer与tkprof工具不同,Trace Analyzer 将普通用户的递归和系统内部的递归调用分开。
4.Trace Analyzer 提供更多的等待事件的细节,更有利于dba做出基于等待事件的优化措施
Event Times Count Max. Total Blocks
waited on Waited Zero Time Wait Waited Accessed
----------------------------------------- --------- --------- ------- ------- --------
PL/SQL lock timer........................ 15 0 5.01 75.08
log file sync............................ 1 0 0.01 0.01
library cache pin........................ 1 0 0.00 0.00
SQL*Net message from client (idle)....... 2 0 17.22 30.21
SQL*Net message to client (idle)......... 3 0 0.00 0.00
total.................................... 22 0 17.22 105.30 0