当用户进程读取数据都Buffer Cache时,或Buffer Cache根据LRU算法进行管理时,都需要扫描LRU List获取可用的Buffer或更改Buffer状态。而Oracle的Buffer Cache是共享内存,可以被众多并发进程访问。当这些扫描发生时必须获取Latch(Latch是Oracle内部的串行锁机制,用于保护共享内存结构),锁定内部结构,防止并发访问损坏内存中的数据。
SQL> col name for a25 SQL> select addr,latch#,name,gets,misses,immediate_misses from v$latch where name='cache buffers lru chain'; ADDR LATCH# NAME GETS MISSES IMMEDIATE_MISSES ---------------- ---------- ------------------------- ---------- ---------- ---------------- 00000000600188A8 145 cache buffers lru chain 276746 8 127
Cache Buffers Lru Chain Latch存在多个子latch,其数量受隐含参数_db_block_lru_latches控制,11G显示为最多64个子latch。
SQL> @?/getparDescr.sql Enter value for get_parameters: db_block_lru_latche old 10: and ksppinm like '%&get_parameters%' new 10: and ksppinm like '%db_block_lru_latche%' NAME TYPE VALUE VALUE DEFAULTS DESCRIBE KSPPIHASH -------------------- ---------- --------------- --------------- --------------------------- ------------------------------ ---------- _db_block_lru_latche 3 64 64 TRUE number of lru latches 224749308 s
可以从v$latch_children视图查看当前各子Latch的使用情况,实际在11G中查看的数量却是参数限制的2倍:
select addr, child#, name, gets, misses, immediate_gets igets, immediate_misses imisses from v$latch_children where name = 'cache buffers lru chain'; ADDR CHILD# NAME GETS MISSES IGETS IMISSES ---------------- ---------- ---------------------------------------- ---------- ---------- ---------- ---------- 00000001F0DF5690 128 cache buffers lru chain 0 0 0 0 00000001F0DF55D0 127 cache buffers lru chain 19 0 1 0 00000001F0DF4FC0 126 cache buffers lru chain 0 0 0 0 ...... 00000001F0D4E170 3 cache buffers lru chain 19 0 1 0 00000001F0D4DB60 2 cache buffers lru chain 0 0 0 0 00000001F0D4DAA0 1 cache buffers lru chain 19 0 1 0
如果Latch竞争激烈,通常采取的方式可以是:
(1) 适当增大Buffer Cache,减少将数据读入Buffer Cache的机会,减少扫描LRU List的竞争。
(2) 适当增加LRU Latch的数量,修改_db_block_lru_latche参数值,通常不建议这么操作。
(3) 通过多缓冲池技术,减少不希望的数据老化和全表扫描等操作队Default池的冲击,从而减少竞争。
转载于:https://blog.51cto.com/onlinekof2001/1623406