Oracle Mutex 等待事件
pin S 等待事件說明,當一個會話(session)試圖去更新一個共享的 Mutex Pin,同時已經有其他會話正在更新(updating)同一個 Shared Mutex Pin。注意,Pin S 的Mutex位於子遊標上,是動態創建的,無法從等待事件中獲得,但是可以在競爭出現的情況下,通過觀察 x$mutex_sleep_history 來獲得。
文檔說明如下:
在 Oracle 官方文檔,關於 cursor pin X 等待事件的說明是:
A session waits on this event when it is requesting an exclusive mutex pin for a cursor object and it must wait because the resource is busy. The mutex pin for a cursor object can be busy either because a session is already holding it exclusive, or there are one or more sessions which are holding shared mutex pin(s). The exclusive waiter must wait until all holders of the pin for that cursor object have released it, before it can be granted. Wait Time:Microseconds
翻譯過來就是:
當一個會話對一個 cursor 對象請求 排他模式的 Mutex pin 時,因為該對象已有 X 或者 S 模式的 Mutex pin 存在,所以必須處於等待。直至所有 X 或 S 模式的 pin 被釋放後,才能夠獲得 X pin。
cursor pin X 等待有三個參數,第一個參數就是 cursor 的 hash value。
文檔說明如下:
需要對 Cursor 執行 Pin X 的操作包括:
- 會話在某些串行化操作時需要獲得 X 模式的 Pin,例如構建一個子遊標;
- 在Cursor 上執行排他操作,如 dbms_shared_pool.purge, keep/unkeep 等;
- 一個或多個進程正在reference 該Mutex (shared mutex pin)
Cursor: Mutex S 等待事件是指,一個會話以共享模式請求一個Mutex,而其他會話以排他模式正在持有Cursor 上的 Mutex。
從文檔說明可以看到,此處的Mutex是位於 Cursor 對象上的固有 Mutex,也就是針對 Parent Cursor 的。這個等待的第一個參數會披露出 SQL 的 Hash Value。
Cursor Mutex X 是當會話對某個 Cursor 請求排他模式鎖,但是該Cursor 上已經有 S 或 X 模式的鎖定,因而產生的等待。
需要持有 Cursor Mutex X 的操作主要有:
- 在父遊標下創建新的子遊標,但是這類操作在11.2之後被 Build Lock 替代,不再需要;
- 捕獲SQL中的綁定變量;
- 更新、生成 SQL 統計信息,主要是 V$SQLSTATS 的內容;
- Cursor Mutex X 主要指對於父遊標的操作;
- Building a new cursor under a parent
- Although this operation is cheaper, building many cursors under a parent cursor is not recommended.
- Capture SQL bind data
- Build or Update statistics blocks
- Mutex is in the parent cursor.
以下是在生產環境中觀察到的實際現象,注意在獲取 cursor:mutex X 的過程中,調用的底層函數是kkscsAddChildNode 這是增加子遊標的操作,需要進一步的獲取排他Mutex ,使用的函數是 kgxExclusive :
關於Mutex 的使用一直在變化之中。
作者簡介:
蓋國強
Oracle ACE總監,中國十大傑出數據庫工程師之一(2006),ITPUB論壇Oracle管理版版主,ITPUB論壇超級版主,《程序員》雜誌特邀專家顧問。蓋國強是國內第一位Oracle ACE及Oracle ACE總監,作為Oracle技術的推廣者,在2010年創建了國內第一個Oracle用戶組ACOUG(ALL China Oracle User Group),並迅速成為國際Oracle用戶組的重要成員。
來源:數據和雲
原文鏈接
最後更新:2017-08-30 11:34:00