RAC資料庫中的'log file sync'等待事件

來源:互聯網
上載者:User

RAC 資料庫中的'log file sync' 等待事件要比單機資料庫中的'log file sync' 等待事件複雜,主要原因是由於RAC 資料庫需要將SCN同步到所有執行個體。

    單機資料庫中的'log file sync' 等待事件,當user session 提交(commit)時,user session會通知LGWR進程將redo buffer中的資訊寫入到redo log file,當LGWR進程完成寫操作後,LGWR再post(通知)user session 寫操作已經完成,user session 接收到LGWR的通知後提交操作才完成。因此user session 在沒有收到LGWR post(通知)之前一致處於等待狀態,具體的等待事件為'log file sync'。在RAC資料庫中為了一致性讀,需要將Commit SCN同步/傳播到所有的節點上。SCN同步/傳播的主要方法有兩種:Lamport SCN 和 immediate commit propagation (BOC)。
    10gR1 及以下版本預設使用Lamport SCN,Lamport SCN方式即一個節點上的commit SCN 不保證立刻同步/傳播到所有節點,也就是說可能延時同步/傳播,對於一些即時性要求高的RAC資料庫Lamport SCN方式是不可取的。如果希望commit SCN 立刻同步/傳播到所有節點,手動修改參數MAX_COMMIT_PROPAGATION_DELAY=1。從10gR2開始預設使用immediate commit propagation (BOC),BOC即一個節點上的commit SCN 立刻同步/傳播到所有節點。

    介紹 immediate commit propagation (BOC)的工作原理:
1. user session 執行提交(commit),user session會通知LGWR進程將redo buffer中的資訊寫入到redo log file;
2. LGWR進程收到user session通知後,將redo buffer中的資訊寫入redo log file,同時LGWR 將COMMIT SCN 同步/傳播給遠端資料庫執行個體的LMS 進程;
3. 遠端資料庫執行個體的LMS將commit SCN同步到本地SCN,然後通知commit執行個體的LMS,表示SCN 同步已經完成;
4. 當commit 執行個體的LMS接收到所有遠端資料庫執行個體的LMS的通知後,commit 執行個體的LMS再通知本地的LGWR 所有節點SCN同步已經完成;

5. LGWR 在完成了IO 操作和LMS進程通知後,LGWR通知user session commit 成功。user session在沒有收到LGWR通知前,一直處於等待log file sync;
    通過以上原理的說明,我們不難看出來導致'log file sync' 等待事件的主要原因有:

1. 磁碟IO 慢導致LGWR進程將redo buffer中的資訊寫入到redo log file速度慢;

2. user session commit過於頻繁;

3. 本地或者遠程伺服器CPU資源不足,導致LMS和/或者LGWR不能及時得到CPU調度,不能正常工作;

4. RAC私人網路效能差,導致LMS同步commit SCN慢;

5. Oracle BUG;

    分析處理'log file sync' 等待事件時的重要log/資訊:

1. AWR

例如:AWR中log file sync 的等待時間與log file parallel write的時間基本相同,因此是由於IO問題導致的log file sync。


2. LGWR and LMS process trace file
例如:LGWR trace檔案中報出下面的資訊,很有可能是IO慢導致的。
Warning: log write time 1000ms, size 2KB
3. OSWatcher <--- 可以協助我們確認伺服器CPU資源使用方式
例如:下面的是OSW中vmstat 的輸出,其中runQ中的進程達到48個,表明當時CPU資源是非常緊張的,會導致LMS/LGWR不能獲得CPU 調度,導致Log file sync等待。
procs          memory                  page                              faults      cpu

r    b  w  avm      free      re  at    pi  po    fr  de    sr    in    sy    cs    us sy id

48  22  0 23877753 30244459    0    0    0    0    0    0    0  153454 2184632 114234  38 60  2

48  22  0 23877753 30244094    0    0    0    0    0    0    0  153694 2181493 114887  36 61  3
4. Alert log
5. Script to Collect Log File Sync Diagnostic Information (lfsdiag.sql) [Document 1064487.1]
    解決'log file sync' 等待事件主要方法:
1. 提高磁碟IO速度
2. 採用批量提交,減少應用commit次數
3. 安裝OSWatcher 定位CPU使用率高的進程
4. 採用專用網路,正確設定網路UDP buffer參數
5. 安裝最新版本資料庫避免bug,具體bug修複的版本參考文檔:
WAITEVENT: "log file sync" Reference Note (Doc ID 34592.1)

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.