2)先將timed_statistics參數(shù)設(shè)置為true,這樣可以使TKPROF工具能提供更多的有意義的信息,方便性能診斷 sec@ora10g> alter session set timed_statistics=true;
Session altered.
3)“高級”之所在,我們這里啟用10046的level 12對當前會話進行跟蹤。 (1)在此,給出10046各level的解釋參考: level 1 to enable the standard SQL_TRACE facility (same as SQL_TRACE=TRUE) 等同于標準的SQL_TRACE=TRUE; level 4 to enable SQL_TRACE and also capture bind variable values in the trace file 啟用SQL_TRACE,并捕捉跟蹤文件中的綁定變量; level 8 to enable SQL_TRACE and also capture wait events into the trace file 啟用SQL_TRACE,并捕捉跟蹤文件中的等待事件; level 12 to enable standard SQL_TRACE and also capture bind variables and wait events 啟用SQL_TRACE,并捕捉跟蹤文件中的綁定變量和等待事件(捕獲信息能力最強)。
(2)對當前會話啟用level 12的跟蹤: sec@ora10g> alter session set events '10046 trace name context forever, level 12';
******************************************************************************** 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 ********************************************************************************
BEGIN DBMS_OUTPUT.GET_LINES(:LINES, :NUMLINES); END;
Misses in library cache during parse: 0 Optimizer mode: ALL_ROWS Parsing user id: 51
Elapsed times include waiting on following events: Event waited on Times Max. Wait Total Waited ---------------------------------------- Waited ---------- ------------ SQL*Net message to client 2 0.00 0.00 SQL*Net message from client 2 5.60 7.74 ********************************************************************************
Misses in library cache during parse: 0 Optimizer mode: ALL_ROWS Parsing user id: 51
Rows Row Source Operation ------- --------------------------------------------------- 1 SORT AGGREGATE (cr=222957 pr=222186 pw=0 time=10686023 us) 100000000 INDEX FAST FULL SCAN PK_T (cr=222957 pr=222186 pw=0 time=100000562 us)(object id 45619)
Elapsed times include waiting on following events: Event waited on Times Max. Wait Total Waited ---------------------------------------- Waited ---------- ------------ SQL*Net message to client 3 0.00 0.00 SQL*Net message from client 3 0.00 0.00 db file scattered read 14249 0.00 1.10 db file sequential read 59 0.00 0.00
Elapsed times include waiting on following events: Event waited on Times Max. Wait Total Waited ---------------------------------------- Waited ---------- ------------ SQL*Net message to client 5 0.00 0.00 SQL*Net message from client 5 5.60 7.74 db file scattered read 14249 0.00 1.10 db file sequential read 59 0.00 0.00
關(guān)于統(tǒng)計表格的標題信息中count、cpu、elapsed、disk、query、current和rows的說明在該trace文件的最前端有一個簡要的說明,這里再分別贅述一下。 count :查詢在此階段執(zhí)行的次數(shù); cpu :該查詢在此階段的CPU時間量,以毫秒為單位; elapsed :花費在此階段上的掛鐘時間,該值比cpu值大的時候,表明存在等待事件; disk :執(zhí)行物理I/O次數(shù); query :在意一致性檢索方式獲得塊時,執(zhí)行邏輯I/O次數(shù); current :邏輯I/O次數(shù); rows :此階段,被處理或受影響的行數(shù)。
4)摘錄等待事件 Elapsed times include waiting on following events: Event waited on Times Max. Wait Total Waited ---------------------------------------- Waited ---------- ------------ SQL*Net message to client 3 0.00 0.00 SQL*Net message from client 3 0.00 0.00 db file scattered read 14249 0.00 1.10 db file sequential read 59 0.00 0.00