1、概述
Oracle 10g InMemory Undo新特性:
通過以前的介紹,可知道Undo的管理方式和常規的資料管理方式是相同的,當進行資料修改時,會在Buffer中建立前鏡像,同時會記錄相應的Redo,然後這些Undo資料同樣會寫出到UNDO SEGMENT上,當進行一致性讀或復原時,可能會產生大量的consistentgets和physical reads。注意到這裡,Undo會產生Redo資訊,又會寫UNDO SEGMENT,進而又可能產生大量讀取I/O,這些都是資源密集型操作。如果能夠縮減Undo在這些環節的Redo與Undo寫出,那麼顯然就可以極大地提升資料庫效能,減少資源的消耗和使用。
從Oracle10g開始,Oracle在資料庫中引入了In Memory Undo(可以被縮寫為IMU)的新技術,使用這一技術,資料庫會在共用記憶體中(Shared Pool)開闢獨立的記憶體地區用於儲存Undo資訊,這樣就可以避免Undo資訊以前在Buffer Cache中的讀寫操作,從而可以進一步的減少Redo產生,同時可以大大減少以前的UNDO SEGMENT的操作。IMU中資料通過暫存、整理與收縮之後也可以寫出到復原段,這樣的寫出提供了有序、批量寫的效能提升。
IMU機制與前面日誌提到的PVRS緊密相關,由於每個IMU Buffer的大小在64~128KB左右,所以僅有特定的小事務可以使用,每個事務會被綁定到一個獨立的閒置IMU Buffer,同時相關的Redo資訊會寫入PVRS中,同樣每個IMU Buffer會由一個獨立的In Memory Undo Latch保護,當IMU Buffer或PVRS寫滿之後,資料庫需要寫出IMU中的資訊。
一個新引入的隱含參數可以控制該特性是否啟用,這個參數是_in_memory_undo,在Oracle 10g中這個參數的預設值是TRUE(不同版本和平台參數的初始設定可能不同):
sys@TQGZS> @GetHidPar.sql
Enter value for par: _in_memory_undo
old 4: AND x.ksppinm LIKE '%&par%'
new 4: AND x.ksppinm LIKE '%_in_memory_undo%'
NAME VALUE DESCRIB
------------------------------ --------------------------------------------------------------------------------
_in_memory_undo TRUE Make in memory undo for top level transactions
IMU的記憶體在Shared Pool中分配,回想一下Redo Log Buffer的記憶體使用量與功能,實際上IMU技術在某種程度上也是參考了Log Buffer的機制,通過以下查詢可以獲得系統當前分配的IMU記憶體:
sys@TQGZS> select * from v$sgastat where name ='KTI-UNDO';
POOL NAME BYTES
------------ ------------------------------ ----------
shared pool KTI-UNDO 1235304
In Memory Undo池預設的會分配3個,用以提供更好的並發:
sys@TQGZS> @GetHidPar.sql
Enter value for par: _imu_pool
old 4: AND x.ksppinm LIKE '%&par%'
new 4: AND x.ksppinm LIKE '%_imu_pool%'
NAME VALUE DESCRIB
------------------------------ --------------------------------------------------------------------------------
_imu_pools 3 in memory undo pools
IMU的使用資訊,如提交次數可以通過V$SYSSTAT視圖查詢:
sys@TQGZS> select name,value from v$sysstat where name like '%commits';
NAME VALUE
------------------------------ -------------
usercommits 2877
IMUcommits 1549
新的記憶體Buffer通過In Memory Undo Latch來進行保護:
sys@TQGZS> select name,gets,misses,immediate_gets,sleeps
2 from v$latch_children where name like '%undo latch';
NAME GETS MISSES IMMEDIATE_GETS SLEEPS
------------------------------ ---------- ---------- -------------- ----------
In memory undolatch 0 0 0 0
In memory undolatch 0 0 0 0
In memory undolatch 0 0 0 0
In memory undolatch 0 0 0 0
In memory undolatch 0 0 0 0
In memory undo latch 0 0 0 0
In memory undolatch 0 0 0 0
In memory undolatch 0 0 0 0
In memory undolatch 0 0 0 0
In memory undolatch 0 0 0 0
In memory undolatch 0 0 0 0
In memory undolatch 0 0 0 0
In memory undolatch 0 0 0 0
In memory undolatch 4 0 2 0
In memory undolatch 214 0 25 0
In memory undolatch 6118 0 3064 0
In memory undolatch 4230 0 1084 0
In memory undolatch 39583 0 2842 0
18 rows selected.
除了前面提到的,還有幾個隱含參數與IMU有關:
·_recursive_imu_transactions:控制遞迴事務是否使用IMU,該參數預設值為False;
sys@TQGZS> @GetHidPar.sql
Enter value for par: _recursive_imu_transactions
old 4: AND x.ksppinm LIKE '%&par%'
new 4: AND x.ksppinm LIKE '%_recursive_imu_transactions%'
NAME VALUE DESCRIB
------------------------------ --------------------------------------------------------------------------------
_recursive_imu_transactions FALSE recursive transactions may be IMU
·_db_writer_flush_imu:控制是否允許DBWR將IMU事務的降級為常規事務,並執行UNDO SEGMENT的寫出操作,預設值為TRUE。
sys@TQGZS> @GetHidPar.sql
Enter value for par: _db_writer_flush_imu
old 4: AND x.ksppinm LIKE '%&par%'
new 4: AND x.ksppinm LIKE '%_db_writer_flush_imu%'
NAME VALUE DESCRIB
------------------------------ --------------------------------------------------------------------------------
_db_writer_flush_imu TRUE If FALSE, DBWR will not downgrade IMU txns for AGING
此外,在RAC環境中,IMU不被支援。
經過不同版本Oracle技術的不斷演化,Oracle的記憶體管理已經和以前大為不同,現在Buffer Cache、Shared Pool、Log Buffer的內容正在不斷交換滲透,Redo、Undo資料都可以部分地儲存在共用池中,Oracle 11g的Result Cache也被記錄在Shared Pool當中。
- The End -