http://www.linuxidc.com/Linux/2012-06/63322.htm
Raw Trace的收集方法
1. 打開Trace,Help > Diagnostics > Trace > Trace > Trace with Binds and Waits
Trace項代表的意思
•No Trace – turns trace off.
•Regular Trace – generates a regular SQL trace by performing the following statement:
ALTER SESSION SET SQL_TRACE = TRUE;
•Trace with Binds – writes bind variable values in the SQL trace file
•Trace with Waits – writes wait events in the SQL trace file
•Trace with Binds and Waits – writes both bind variable values and wait events in the SQL trace file
2.執行業務功能
3.關閉Trace,Help > Diagnostics > Trace > Trace > No Trace
系統會彈出一個窗口,告訴你Trace文件所在的目錄。
這個目錄實際上是數據庫系統參數表(v$parameter)中的user_dump_dest的值,可以執行下邊的SQL來找到Trace文件所在的目錄
1.SELECT value FROM v$parameter WHERE name = 'user_dump_dest';
2.
3.Output:/slot/ems7061/Oracle/db/tech_st/11.2.0/admin/az1mu213_rws60145rems/diag/rdbms/az1mu213/az1mu213/trace
trace文件名後邊的那個數字是Database Server PID,也可以從Help>About中找到。
TKPROF
之前我們收集的trace日誌仍爲Raw Trace,如果要做性能分析的話,往往要轉換爲TKPROF,TKPROF可以把Raw Trace轉換爲更易讀的形式。
1.TKPROF Command
2.$tkprof tracefile outputfile [explain= ] [table= ] [print= ] [insert= ] [sys= ] [sort= ] ...
3.
4.Sample:
5.TKPROF raw_trace.trc OUTPUTA.TKPROF EXPLAIN=scott/tiger SYS=NO SORT=(EXECPU,FCHCPU)
tracefile:你要分析的trace文件
outputfile:格式化後的文件
explain=user/password@connectstring
table=schema.tablename
注1:這兩個參數是一起使用的,通過連接數據庫對在trace文件中出現的每條sql語句查看執行計劃,並將之輸出到outputfile中
注2:該table必須是數據庫中不存在的,如果存在會報錯
print=n:只列出最初N個sql執行語句
insert=filename:會產生一個sql文件,運行此文件可將收集到的數據insert到數據庫表中
sys=no:過濾掉由sys執行的語句
record=filename:可將非嵌套執行的sql語句過濾到指定的文件中去
waits=yes|no:是否統計任何等待事件
aggregate=yes|no:是否將相同sql語句的執行信息合計起來,默認爲yes
sort=option:設置排序選項,選項如下:
prscnt:number of times parse was called
prscpu:cpu time parsing
prsela:elapsed time parsing
prsdsk:number of disk reads during parse
prsqry:number of buffers for consistent read during parse
prscu:number of buffers for current read during parse
prsmis:number of misses in library cache during parse
execnt:number of execute was called
execpu:cpu time spent executing
exeela:elapsed time executing
exedsk:number of disk reads during execute
exeqry:number of buffers for consistent read during execute
execu:number of buffers for current read during execute
exerow:number of rows processed during execute
exemis:number of library cache misses during execute
fchcnt:number of times fetch was called
fchcpu:cpu time spent fetching
fchela:elapsed time fetching
fchdsk:number of disk reads during fetch
fchqry:number of buffers for consistent read during fetch
fchcu:number of buffers for current read during fetch
fchrow:number of rows fetched
userid:userid of user that parsed the cursor
1.Tkprof: Release 9.2.0.1.0 - Production on Tue Dec 24 15:32:43 2002
2.Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved.
3.
4.Trace file: ORCL102_ora_3064.trc
5.
6.Sort options: default
7.
8.********************************************************************************
9.count = number of times OCI procedure was executed
10.cpu = cpu time in seconds executing
11.elapsed = elapsed time in seconds executing
12.disk = number of physical reads of buffers from disk
13.query = number of buffers gotten for consistent read
14.current = number of buffers gotten in current mode (usually for update)
15.rows = number of rows processed by the fetch or execute call
16.********************************************************************************
17.
18.select *
19.from
20. employee where emp_id = 3737
21.
22.call count cpu elapsed disk query current rows
23.------- ------ -------- ---------- ---------- ---------- ---------- ----------
24.Parse 10 0.00 0.03 0 0 0 0
25.Execute 10 0.00 0.00 0 0 0 0
26.Fetch 20 0.34 0.35 72 4730 0 10
27.------- ------ -------- ---------- ---------- ---------- ---------- ----------
28.total 40 0.34 0.39 72 4730 0 10
29.
30.Misses in library cache during parse: 1
31.Optimizer goal: CHOOSE
32.Parsing user id: 59
33.
34.Rows Row Source Operation
35.------- ---------------------------------------------------
36. 1 TABLE ACCESS FULL EMPLOYEE
本篇文章來源於 Linux公社網站(www.linuxidc.com) 原文鏈接:http://www.linuxidc.com/Linux/2012-06/63322p2.htm
query1:Select value from v$parameter
where name = 'user_dump_dest';
query2: Select oracle_process_id
from fnd_concurrent_requests
where request_id = 2754278
command:tkprof dv11_ora_7830_OPERATIONS_CR2759648.trc dv11_ora_7830_OPERATIONS_CR2759648.tkp sort=prsdsk,exedsk,fchdsk
1,在併發程序定義界面勾上trace選項
2,執行併發程序
3,query1找到生成的trc文件的路徑,query2找到文件名中的processing_id
4,tkprof生成tkp文件
5,選取tkp文件中的前5個query在Toad裏Explain Plan
使用tkprof
命令在DV11
要先運行一下環境變量的文件
. ./appenv.sh $env $bash
appenv.sh所在目錄爲:/rdbms/apps1159
要先cd到/u01/oracle/DV11/dv11db/9.2.0/admin/DV11_prcsgisol03/udump目錄下,再執行tkprof tracefile outputfile