10 使用性能視圖調優

 

10.2.3表的等待事件及其潛在的原因

Wait Event General Area Possible Causes Look for / Examine

buffer busy waits

Buffer cache, DBWR

Depends on buffer type. For example, waits for an index block may be caused by a primary key that is based on an ascending sequence.

Examine V$SESSION while the problem is occurring to determine the type of block in contention.

free buffer waits

Buffer cache, DBWR, I/O

Slow DBWR (possibly due to I/O?)

Cache too small

Examine write time using operating system statistics. Check buffer cache statistics for evidence of too small cache.

db file scattered read

I/O, SQL statement tuning

Poorly tuned SQL

Slow I/O system

Investigate V$SQLAREA to see whether there are SQL statements performing many disk reads. Cross-check I/O system and V$FILESTAT for poor read time.

db file sequential read

I/O, SQL statement tuning

Poorly tuned SQL

Slow I/O system

Investigate V$SQLAREA to see whether there are SQL statements performing many disk reads. Cross-check I/O system and V$FILESTAT for poor read time.

enqueue waits (waits starting with enq: )

Locks

Depends on type of enqueue

Look at V$ENQUEUE_STAT .

library cache latch waits: library cache , library cache pin , and library cache lock

Latch contention

SQL parsing or sharing

Check V$SQLAREA to see whether there are SQL statements with a relatively high number of parse calls or a high number of child cursors (column VERSION_COUNT ). Check parse statistics in V$SYSSTAT and their corresponding rate for each second.

log buffer space

Log buffer, I/O

Log buffer small

Slow I/O system

Check the statistic redo buffer allocation retries in V$SYSSTAT . Check configuring log buffer section in configuring memory chapter. Check the disks that house the online redo logs for resource contention.

log file sync

I/O, over- committing

Slow disks that store the online logs

Un-batched commits

Check the disks that house the online redo logs for resource contention. Check the number of transactions (commits + rollbacks ) each second, from V$SYSSTAT .

 

10.2.4與解析相關的統計信息

SELECT NAME, VALUE
FROM V$SYSSTAT
WHERE NAME IN ( 'parse time cpu', 'parse time elapsed',
'parse count (hard)', 'CPU used by this session' );

1.比值parse time CPU / parse time elapsed越接近於1,表明解析過程中在等待高爭用資源時的時間越少。

2.比值parse time CPU / CPU used by this session越接近於0,表明CPU用於解析SQL越少。

 

10.3 等待事件統計信息

1.SQL*Net Events

2.buffer busy waits

3.db file scattered read

4.db file sequential read

5.direct path read and direct path read temp

6.direct path write and direct path write temp

7.enqueue waits

8.events in wait class other

9.free buffer waits

在單CPU而無法使用多DBWR(通過系統變量DB_WRITER_PROCESSES 設置,參數類型:integer ),且異步(asynchronous)I/O不可用的情況下,多個I/O從進程(mutiple I/O slaves,通過系統變量DB_IO_SLAVES 設置,參數類型:integer )是很有用的解決辦法。I/O從進程只能用於單DBWR進程下。

一般DBWR遇到瓶頸問題時,首先考慮的是系統是否支持異步I/O,在肯定的情況下設置異步I/O(通過系統變量DISK_ASYNCH_IO 設置,參數類型:boolean ,可選值:true、false),然後觀察問題是否得到緩解。其次,如果系統在異步I/O不可用,或者異步I/O已經設置時,DBWR仍存在瓶頸的情況下,那麼再考慮使用設置多DBWR進程來解決。最後,僅當無法配置多DBWR進程的情況下,使用I/O slaves

10.latch events

Table 10-2 Latch Wait Event

Latch SGA Area Possible Causes Look For:

Shared pool, library cache

Shared pool

Lack of statement reuse

Statements not using bind variables

Insufficient size of application cursor cache

Cursors closed explicitly after each execution

Frequent logon/logoffs

Underlying object structure being modified (for example truncate)

Shared pool too small

Sessions (in V$SESSTAT ) with high:

  • parse time CPU

  • parse time elapse d

  • Ratio of parse count (hard) / execute coun t

  • Ratio of parse count (total) / execute count

Cursors (in V$SQLAREA /V$SQLSTATS ) with:

  • High ratio of PARSE_CALLS / EXECUTIONS

  • EXECUTIONS = 1 differing only in literals in the WHERE clause (that is, no bind variables used)

  • High RELOADS

  • High INVALIDATIONS

  • Large (> 1mb) SHARABLE_MEM

cache buffers lru chain

Buffer cache LRU lists

Excessive buffer cache throughput. For example, inefficient SQL that accesses incorrect indexes iteratively (large index range scans) or many full table scans

DBWR not keeping up with the dirty workload; hence, foreground process spends longer holding the latch looking for a free buffer

Cache may be too small

Statements with very high logical I/O or physical I/O, using unselective indexes

cache buffers chains

Buffer cache buffers

Repeated access to a block (or small number of blocks), known as a hot block

Sequence number generation code that updates a row in a table to generate the number, rather than using a sequence number generator

Index leaf chasing from very many processes scanning the same unselective index with very similar predicate

Identify the segment the hot block belongs to

row cache objects

通過以下語句查詢有可能未進行綁定變量的SQL

1. SELECT SQL_TEXT
  FROM V$SQL
 WHERE EXECUTIONS < 4
 ORDER BY SQL_TEXT;

2.SELECT SUBSTR(SQL_TEXT, 1, 60), COUNT(*)
  FROM V$SQL
 WHERE EXECUTIONS < 4
 GROUP BY SUBSTR(SQL_TEXT, 1, 60)
 HAVING COUNT(*) > 1;
執行次數(EXECUTIONS)越少,SQL越相似,未進行綁定變量的可能性越大。

3.SELECT SQL_TEXT FROM V$SQL WHERE PLAN_HASH_VALUE IN
  (SELECT PLAN_HASH_VALUE
     FROM V$SQL
    GROUP BY PLAN_HASH_VALUE HAVING COUNT(*) > 4)
  ORDER BY PLAN_HASH_VALUE;

以上當PARSE_CALLS越接近EXECUTIONS時,表明你在持續的重新解析這個SQL, PARSE_CALLS較高的SQL意味着需要優化了。

11.log file parallel write

12.library cache pin

13.library cache lock

14.log buffer space

一般原因是重做日誌的產生速度快於LGWR從日誌緩存寫出至日誌文件的速度。解決辦法:一:是否log buffer太小。二:系統是否存在I/O瓶頸。

15.log file switch

一般發生於日誌文件轉換(一:歸檔需求。二:檢測點不完整)

16.log file sync

一、如果平均等待時間低,而等待次數較高時,查看應用程序中是否每次INSERT後執行了commit操作,使用批量提交(batching COMMITs)可降低等待次數。

二、如果平均等待時間較高,檢查何問題造成大量的等待時間,例如,是緩慢的I/O,則可嘗試以下辦法解決。

1.減少重做日誌日誌文件所在硬盤的I/O操作,或者爲重做日誌更換專用硬盤。

2.爲歸檔日誌備用不通的磁盤,使日誌寫進程歸檔操作所帶來的的影響最小華。

3.將重做日誌轉移至更快的磁盤設備或者I/O子系統(例如,將磁盤陣列RAID5換爲RAID1方式)

4.考慮使用裸設備(或者磁盤廠商所提供的模擬裸設備)提高寫入速度。

5.具體應用程序中,採用批量每N行數據提交,替代每行數據提交的做法。

17.rdbms ipc reply

等待一個後臺進程的回覆

 

10.4空閒等待進程

Table 10-3 Idle Wait Events

Wait Name Background Process Idle Event User Process Idle Event Parallel Query Idle Event Shared Server Idle Event Oracle Real Application Clusters Idle Event

dispatcher timer

.

.

.

X

.

pipe get

.

X

.

.

.

pmon timer

X

.

.

.

.

PX Idle Wait

.

.

X

.

.

PX Deq Credit: need buffer

.

.

X

.

.

rdbms ipc message

X

.

.

.

.

smon timer

X

.

.

.

.

SQL*Net message from client

.

X

.

.

.

virtual circuit status

.

.

.

X

.

 

查詢某個會話的各個等待事件

1.select  a.sid,
       a.event,
       a.time_waited,
       round(a.time_waited/c.sum_time_waited* 100  ,  2 ) ||  '%'  pct_wait_time,
       round(( sysdate  - b.LOGON_TIME) *  24 ) hours_connected
   from  v$session_event a,
       v$session b,
       ( select  sid,  sum (time_waited) sum_time_waited
           from  v$session_event
        
          where  event  not   in  ( 'null event' 'SQL*Net message to client' ,
                 'pmon timer' 'pipe get' 'smon timer' 'jobq slave wait' ,
                 'rdbms ipc message' 'rdbms ipc reply' 'PX Deq: Join ACK' ,
                 'PX Deq: Signal ACK'
         having   sum (time_waited) >  0    -- 對group by 產生結果的挑選
          group   by  sid) c
  where  a.sid = b.sid
    and  a.sid = c.sid
    and  a.TIME_WAITED >  0
    and  a.sid = &1
  order   by  hours_connected  desc , pct_wait_time

2.查詢各會話等待事件

select sid,event,p1,p1text from v$session_wait;

3.查詢具體會話運行中的sql語句

SELECT   sql_text
    FROM v$sqltext a
   WHERE a.hash_value = (SELECT sql_hash_value
                           FROM v$session b
                          WHERE b.SID = &sid)
ORDER BY piece ASC

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