1. 程式人生 > >Oracle v$session_wait

Oracle v$session_wait

V$SESSION_WAIT View
The V$SESSION_WAIT view provides detailed information about the event or resource that each session is waiting for. This view contains only one row of information per session, active or inactive,

at any given time. Unlike the other views, this view displays session-level wait information in real time. Because of this, it may very well show different results each time you query the view.

V$SESSION_WAIT 檢視記錄了每個session等待事件或資源的詳細資訊,每個session在檢視中只記錄一條記錄。包括 active和inactive兩種狀態,與其他動態效能檢視不同的是,該檢視中的資訊是實時的,所以每次查詢 的結果可能就不一樣。

該檢視的表結構如下:

  1. SQL> desc v$session_wait

  2. Name Type Nullable Default Comments

  3. --------------- ------------ -------- ------- --------

  4. SID NUMBER Y

  5. SEQ# NUMBER Y

  6. EVENT VARCHAR2(64) Y

  7. P1TEXT VARCHAR2(64) Y

  8. P1 NUMBER Y

  9. P1RAW RAW(4) Y

  10. P2TEXT VARCHAR2(64) Y

  11. P2 NUMBER Y

  12. P2RAW RAW(4) Y

  13. P3TEXT VARCHAR2(64) Y

  14. P3 NUMBER Y

  15. P3RAW RAW(4) Y

  16. WAIT_CLASS_ID NUMBER Y Starting Oracle10g

  17. WAIT_CLASS# NUMBER Y Starting Oracle10g

  18. WAIT_CLASS VARCHAR2(64) Y Starting Oracle10g

  19. WAIT_TIME NUMBER Y

  20. SECONDS_IN_WAIT NUMBER Y

  21. STATE VARCHAR2(19) Y

As you already know, the column SID shows the session identifier, and EVENT contains the name of the event. The columns P1, P2, and P3 contain specific information about the event and identify a

specific resource the session is waiting for. The interpretation of these values is event dependent. The columns P1RAW, P2RAW, and P3RAW contain the hexadecimal representation of the values

in P1, P2 and P3, respectively. To help you reference what these values pertain to, the columns P1TEXT, P2TEXT, and P3TEXT provide the description for columns P1, P2 and P3, respectively.

The column SEQ# is an internal sequence number for the event related to the session. It increments each time the session waits on the event. The WAIT_TIME column records the amount of time the

session has waited for. A negative value denotes unknown wait time, a value equal to zero means that the session is still waiting, and a value greater than zero is the actual wait time. 

WAIT_TIME 列記錄了會話的等待時間,負值表示未知的等待時間,等待0表示正在等待,大於0表示實際等待的時間,

The column SECONDS_IN_WAIT shows wait time in seconds while the session is waiting on the event. The STATE column shows the current wait status. The trio ofSTATE, WAIT_TIME, and
SECONDS_IN_WAIT should be evaluated together, and the next section shows you how to do that. The WAIT_CLASS_ID, WAIT_CLASS#, and WAIT_CLASS columns are introduced in Oracle

Database 10g Release 1 to support the wait event classification feature.

應該將STATE, WAIT_TIME, and SECONDS_IN_WAIT三列的資料一起評估,接下來的章節會告訴如何去看這三列的值。

How to Use V$SESSION_WAIT View
A good time to query the V$SESSION_WAIT view is when you get a call about a slow running application and you want to investigate what the application is doing at that particular moment. Due
to its real-time nature, you have to query this view repeatedly, most likely in quick successions. You may see different wait events cycle through quickly, which means the application is actively
working, or you may see the application continue to wait on the same event, which means it could be idle or actively waiting on a particular resource such as a lock, a latch or, in case of a resumable
session (from Oracle9i Database), a disk space–related issue. Obviously, this view is useful only for current waits and does not provide a history of past wait events. However, that is changed in Oracle Database 10g Release 1. See the “V$SESSION_WAIT_HISTORY View” section for more information. As explained in the previous section, P1, P2, and P3 are attributes that describe the wait event they
are associated with. P1RAW, P2RAW, and P3RAW are the hexadecimal equivalents of P1, P2, and P3. You should familiarize yourself with the attributes of common wait events, but in case you
forget, you can get their descriptions from the P1TEXT, P2TEXT, and P3TEXT columns. For rootcause analysis, you must translate the attributes into meaningful information. For example, you can
obtain the object name that the db file sequential read and db file scattered read events are
referencing by translating their P1 and P2 values. Likewise, you can find out the name of the latch
that the session is waiting on by translating the P2 value. No doubt this can be a very tedious task if
you try to do it manually. By the time you successfully translate one event, many other events could
go by unnoticed. Oracle Database 10g Release 1 simplifies this task for latch and enqueue wait events. Common
latches have their own wait events, for example, latch: redo copy and latch: cache buffers chains.
All enqueues have their own wait events, for example, enq: TX - row lock contention and enq: ST - contention.
The STATE column has four possible values: WAITED UNKNOWN TIME, WAITED SHORT TIME, WAITING, and WAITED KNOWN TIME, and their meanings are as follows:

  • WAITED UNKNOWN TIME simply means that the TIMED_STATISTICS initialization parameter is set to FALSE and Oracle is unable to determine the wait time. In this case, the WAIT_TIME column shows –2.
  • WAITED SHORT TIME means the previous wait was less than one centisecond. In this case, the WAIT_TIME column shows –1.
  • WAITING means that the session is currently waiting and the WAIT_TIME column shows 0, but you can determine the time spent on this current wait from the SECONDS_IN_WAIT

Note In Oracle Database 10g Release 1 the V$SESSION_WAIT view is wholly incorporated into the V$SESSION view so that you can get pertinent information about the user session without having to join the two views.

批註:從10g Release 1開始,V$SESSION_WAIT中的資訊完全包含在V$SESSION檢視中了,不用再關聯這兩個檢視進行查詢了。

  • WAITED KNOWN TIME means Oracle is able to determine the duration of the last wait and the time is posted in theWAIT_TIME column.

STATE 列包括四個狀態值,下面分別作說明:

WAITED UNKNOWN TIME:意味著初始化引數TIMED_STATISTICS=FALSE,這時Oracle不確定等待時間,這種時的WAIT_TIME列的值為-2

WAITED SHORT TIME       :意味著之前 的等待不超過1釐秒,這時的WAIT_TIME值為-1

WAITING                               :意味著當前session正處理等待狀態,這時的WAIT_TIME值為0,但是通過SECONDS_IN_WAIT列的值可以知道已經等了多長時間。

WAITED KNOWN TIME      :意味著Oracle已經確定最後的持續時間的等待,這個值在WAIT_TIME列中。

上面的STAT列的不同值 ,闡明 瞭如何結合STATE, WAIT_TIME, and SECONDS_IN_WAIT這三列評估SESSION的等待情況。

When monitoring the V$SESSION_WAIT view, pay particular attention to the events with STATE=WAITING. This indicates the sessions are actively waiting on the event. The SECONDS_IN_WAIT column shows how long the sessions have been waiting. Also, bear in mind that you should not judge performance based on just one wait occasion. If you want to know how much time a session has waited on a particular wait event, you should consult theV$SESSION_EVENT view.