ITPub博客

首页 > 数据库 > Oracle > oracle 11g latch之系列一

oracle 11g latch之系列一

原创 Oracle 作者:wisdomone1 时间:2015-11-01 22:31:06 0 删除 编辑

背景

   为了学习理解oracle latch,了解下与latch相关的一些参数及其含义,于是便有此文,oracle latch原理及机制是非常复杂的,我们会写一个系列,力争
对它有一个整体的理解,提各分析问题的能力,进一步整合oracle的体系架构。   


结论

1,测试数据库版本为oracle 11.2.0.1


2,与latch spinning相关的参数为:
   _sping_count控制请求获取一个latch spinning的次数,而_kgx_spin_count控制mutex的spinning次数


3,与latch sleeping相关的参数
   可见_max_sleep_holding_latch指定持有一个latch的latch sleeping的次数
   还有其它的参数为:
   _max_exponential_sleep,不过其值为0,且此参数含义仍未知,须进一步测试


4,与latch相关的参数就非常多了,本文主要测试了 _db_block_lru_latches ,会控制simulator lru latch的子latch个数,且其参数不能调大也不能调小,只能是8


5,从4引申出,ORACLE某些核心的隐含参数不参进行调节,即使你调了,还是会恢复原状,因为它的值是经过严密测试,不能随便调整


6,oracle v$latchname与v$latch是1对1关系


7,有些latch有子latch,即相关数据要在v$latch,v$latch_parent,v$latch_childrent获取
  如果有些latch无子latch,相关数据只能在v$latch及v$latch_parent获取


8, 经过测试发现,就是有些latch有子latch,而有些latch呢,却没有子latch
ORACLE为何这样设计呢,它的目的和目标何在呢,这是一个很值得思考的问题,我们将在下文进行继续测试

9,本文还掌握到一个分析思路,即两端分析法,先基于一端进行分析,尝试分析其各种可能分支;如果还不行
  换成另一端进行分析,同理,尝试分析其各种可能分支,这是收获最大的地方




测试



1,数据库版本
SQL> select * from v$version where rownum=1;


BANNER
----------------------------------------------------------------------------------------------------
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production


2,与latch spinning相关的参数
可见_sping_count控制请求获取一个latch spinning的次数,而_kgx_spin_count控制mutex的spinning次数


NAME_1                                             VALUE_1                                            DESC1
-------------------------------------------------- -------------------------------------------------- --------------------------------------------------
_spin_count                                        1                                                  Amount to spin waiting for a latch
_kgx_spin_count                                    255                                                Mutex spin count


3,与latch sleeping相关的参数
可见_max_sleep_holding_latch指定持有一个latch的latch sleeping的次数
_max_exponential_sleep


NAME_1                                             VALUE_1                                            DESC1
-------------------------------------------------- -------------------------------------------------- --------------------------------------------------
_max_sleep_holding_latch                           4                                                  max time to sleep while holding a latch
_max_exponential_sleep                             0                                                  max sleep during exponential backoff
_high_priority_process_num_yields_before_sleep     1000                                               the number of yields performed by high priority pr
                                                                                                      ocessesbefore they sleep


_fg_sync_sleep_usecs                               0                                                  Log file sync via usleep
_parallel_server_sleep_time                        10                                                 sleep time between dequeue timeouts (in 1/100ths)




4,与latch相关的参数
NAME_1                                             VALUE_1                                            DESC1
-------------------------------------------------- -------------------------------------------------- --------------------------------------------------
_latch_recovery_alignment                          65534                                              align latch recovery structures
_latch_miss_stat_sid                               0                                                  Sid of process for which to collect latch stats
_max_sleep_holding_latch                           4                                                  max time to sleep while holding a latch
_latch_class_0                                                                                        latch class 0
_latch_class_1                                                                                        latch class 1
_latch_class_2                                                                                        latch class 2
_latch_class_3                                                                                        latch class 3
_latch_class_4                                                                                        latch class 4
_latch_class_5                                                                                        latch class 5
_latch_class_6                                                                                        latch class 6
_latch_class_7                                                                                        latch class 7


NAME_1                                             VALUE_1                                            DESC1
-------------------------------------------------- -------------------------------------------------- --------------------------------------------------
_latch_classes                                                                                        latch classes override
_ultrafast_latch_statistics                        TRUE                                               maintain fast-path statistics for ultrafast latche
                                                                                                      s


_enable_reliable_latch_waits                       TRUE                                               Enable reliable latch waits
_session_idle_bit_latches                          0                                                  one latch per session or a latch per group of sess
                                                                                                      ions


_num_longop_child_latches                          1                                                  number of child latches for long op array
_session_allocation_latches                        1                                                  one latch per group of sessions
_enqueue_hash_chain_latches                        1                                                  enqueue hash chain latches


NAME_1                                             VALUE_1                                            DESC1
-------------------------------------------------- -------------------------------------------------- --------------------------------------------------
_lm_drm_xlatch                                     0                                                  dynamic remastering forced exclusive latches
_lm_num_pt_latches                                 128                                                number of latches in the object affinity hash tabl
                                                                                                      e


_lm_lmon_nowait_latch                              TRUE                                               if TRUE makes lmon get nowait latches with timeout
                                                                                                       loop


_gcs_latches                                       0                                                  number of gcs resource hash latches to be allocate
                                                                                                      d per LMS process


_disable_latch_free_SCN_writes_via_32cas           FALSE                                              disable latch-free SCN writes using 32-bit compare


NAME_1                                             VALUE_1                                            DESC1
-------------------------------------------------- -------------------------------------------------- --------------------------------------------------
                                                                                                       & swap


_disable_latch_free_SCN_writes_via_64cas           FALSE                                              disable latch-free SCN writes using 64-bit compare
                                                                                                       & swap


_db_block_lru_latches                              8                                                  number of lru latches
_db_block_hash_latches                             8192                                               Number of database block hash latches
_db_blocks_per_hash_latch                                                                             Number of blocks per hash latch
_gc_latches                                        8                                                  number of latches per LMS process
_flashback_copy_latches                            10                                                 Number of flashback copy latches
_ktc_latches                                       0                                                  number of ktc latches


NAME_1                                             VALUE_1                                            DESC1
-------------------------------------------------- -------------------------------------------------- --------------------------------------------------
_ktu_latches                                       0                                                  number of KTU latches
_kgl_latch_count                                   0                                                  number of library cache latches
_kgx_latches                                       1024                                               # of mutex latches if CAS is not supported.
_k2q_latches                                       0                                                  number of k2q latches
_cp_num_hash_latches                               1                                                  connection pool number of hash latches
_px_freelist_latch_divisor                         2                                                  Divide the computed number of freelists by this po
                                                                                                      wer of 2


_deq_ht_child_latches                              8                                                  deq ht child latches


37 rows selected.


SQL> 


5,我们以上述_db_block_lru_latches参数为例,结合实际进一步理解下
可见lru latches共计8个
_db_block_lru_latches                              8                                                  number of lru latches


SQL> select latch#,name,hash from v$latchname where lower(name) like '%lru%';


    LATCH# NAME                                 HASH
---------- ------------------------------ ----------
       145 cache buffers lru chain        3559635447
       158 simulator lru latch             405505728
       197 mapped buffers lru chain         93631960
       478 KFC LRU latch                  3390864701




SQL> select addr,latch#,level#,name,hash from v$latch_parent where latch#=145 and name='cache buffers lru chain';


ADDR                 LATCH#     LEVEL# NAME                                 HASH
---------------- ---------- ---------- ------------------------------ ----------
00000000600188A8        145          2 cache buffers lru chain        3559635447


可见cache buffers lru chain共计16个子latch,可见_db_block_lru_latches参数并不是控制cache buffers lru chain的子latch的个数
SQL> select addr,latch#,child#,level#,name,hash from v$latch_children where latch#=145 and name='cache buffers lru chain' order by 3;


ADDR                 LATCH#     CHILD#     LEVEL# NAME                                 HASH
---------------- ---------- ---------- ---------- ------------------------------ ----------
00000000DA70EAE8        145          1          2 cache buffers lru chain        3559635447
00000000DA70EBA8        145          2          2 cache buffers lru chain        3559635447
00000000DA71A048        145          3          2 cache buffers lru chain        3559635447
00000000DA71A108        145          4          2 cache buffers lru chain        3559635447
00000000DA7255A8        145          5          2 cache buffers lru chain        3559635447
00000000DA725668        145          6          2 cache buffers lru chain        3559635447
00000000DA730B08        145          7          2 cache buffers lru chain        3559635447
00000000DA730BC8        145          8          2 cache buffers lru chain        3559635447
00000000DA73C068        145          9          2 cache buffers lru chain        3559635447
00000000DA73C128        145         10          2 cache buffers lru chain        3559635447
00000000DA7475C8        145         11          2 cache buffers lru chain        3559635447


ADDR                 LATCH#     CHILD#     LEVEL# NAME                                 HASH
---------------- ---------- ---------- ---------- ------------------------------ ----------
00000000DA747688        145         12          2 cache buffers lru chain        3559635447
00000000DA752B28        145         13          2 cache buffers lru chain        3559635447
00000000DA752BE8        145         14          2 cache buffers lru chain        3559635447
00000000DA75E088        145         15          2 cache buffers lru chain        3559635447
00000000DA75E148        145         16          2 cache buffers lru chain        3559635447


16 rows selected.




6,我们换个思路,调整下_db_block_lru_latches的值,看上述数据有无变化,如无变化,表明参数_db_block_lru_latches确实与cache buffers lru chain无关
经测试,确实无关
SQL> alter system set "_db_block_lru_latches"=10;
alter system set "_db_block_lru_latches"=10
                 *
ERROR at line 1:
ORA-02095: specified initialization parameter cannot be modified




SQL> alter system set "_db_block_lru_latches"=10 scope=spfile;


System altered.


SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup
ORACLE instance started.


Total System Global Area 2137886720 bytes
Fixed Size                  2215064 bytes
Variable Size            1409287016 bytes
Database Buffers          721420288 bytes
Redo Buffers                4964352 bytes
Database mounted.
Database opened.
SQL> 


可见虽然显式调整了此参数值,ORACLE内核还是恢复了原值,可见有些参数并非想改就改,ORACLE内部是有一种非常复杂的算法控制的
NAME_1                                             VALUE_1                                            DESC1
-------------------------------------------------- -------------------------------------------------- --------------------------------------------------
_db_block_lru_latches                              8                                                  number of lru latches


SQL> select latch#,name,hash from v$latchname where lower(name) like '%lru%';


    LATCH# NAME                                 HASH
---------- ------------------------------ ----------
       145 cache buffers lru chain        3559635447
       158 simulator lru latch             405505728
       197 mapped buffers lru chain         93631960
       478 KFC LRU latch                  3390864701


SQL> select addr,latch#,level#,name,hash from v$latch_parent where latch#=145 and name='cache buffers lru chain';


ADDR                 LATCH#     LEVEL# NAME                                 HASH
---------------- ---------- ---------- ------------------------------ ----------
00000000600188A8        145          2 cache buffers lru chain        3559635447




SQL> select addr,latch#,child#,level#,name,hash from v$latch_children where latch#=145 and name='cache buffers lru chain' order by 3;


ADDR                 LATCH#     CHILD#     LEVEL# NAME                                 HASH
---------------- ---------- ---------- ---------- ------------------------------ ----------
00000000DA70EAE8        145          1          2 cache buffers lru chain        3559635447
00000000DA70EBA8        145          2          2 cache buffers lru chain        3559635447
00000000DA71A048        145          3          2 cache buffers lru chain        3559635447
00000000DA71A108        145          4          2 cache buffers lru chain        3559635447
00000000DA7255A8        145          5          2 cache buffers lru chain        3559635447
00000000DA725668        145          6          2 cache buffers lru chain        3559635447
00000000DA730B08        145          7          2 cache buffers lru chain        3559635447
00000000DA730BC8        145          8          2 cache buffers lru chain        3559635447
00000000DA73C068        145          9          2 cache buffers lru chain        3559635447
00000000DA73C128        145         10          2 cache buffers lru chain        3559635447
00000000DA7475C8        145         11          2 cache buffers lru chain        3559635447


ADDR                 LATCH#     CHILD#     LEVEL# NAME                                 HASH
---------------- ---------- ---------- ---------- ------------------------------ ----------
00000000DA747688        145         12          2 cache buffers lru chain        3559635447
00000000DA752B28        145         13          2 cache buffers lru chain        3559635447
00000000DA752BE8        145         14          2 cache buffers lru chain        3559635447
00000000DA75E088        145         15          2 cache buffers lru chain        3559635447
00000000DA75E148        145         16          2 cache buffers lru chain        3559635447


16 rows selected.




7,继续参数_db_block_lru_latches确实与cache buffers lru chain无关,那问题来了,它与什么有关呢?
我想,它既然与cachd buffers lru chain无关,肯定与其它的lru相关的latch有关
SQL> select latch#,name,hash from v$latchname where lower(name) like '%lru%';


    LATCH# NAME                                 HASH
---------- ------------------------------ ----------
       145 cache buffers lru chain        3559635447
       158 simulator lru latch             405505728
       197 mapped buffers lru chain         93631960
       478 KFC LRU latch                  3390864701


先看下simulator lru latch


SQL> select addr,latch#,level#,name,hash from v$latch_parent where latch#=158;


ADDR                 LATCH#     LEVEL# NAME                                 HASH
---------------- ---------- ---------- ------------------------------ ----------
000000006001B930        158          6 simulator lru latch             405505728


可见simulator lru latch的子latch正好是8个,那么是它吗,我们说是有可能的,为了确保万无一失,我们再看其它与lru相关的子latch的数量
SQL> select addr,latch#,child#,level#,name,hash from v$latch_children where latch#=158;


ADDR                 LATCH#     CHILD#     LEVEL# NAME                                 HASH
---------------- ---------- ---------- ---------- ------------------------------ ----------
00000000DA75DF20        158          8          6 simulator lru latch             405505728
00000000DA7529C0        158          7          6 simulator lru latch             405505728
00000000DA747460        158          6          6 simulator lru latch             405505728
00000000DA73BF00        158          5          6 simulator lru latch             405505728
00000000DA7309A0        158          4          6 simulator lru latch             405505728
00000000DA725440        158          3          6 simulator lru latch             405505728
00000000DA719EE0        158          2          6 simulator lru latch             405505728
00000000DA70E980        158          1          6 simulator lru latch             405505728


8 rows selected.




再看下mapped buffers lru chain,可见此latch没有子latch,我们再引申一下,就是有些latch有子latch,而有些latch呢,却没有子latch
ORACLE为何这样设计呢,它的目的和目标何在呢,这是一个很值得思考的问题,我们将在下文进行继续测试
SQL> select addr,latch#,level#,name,hash from v$latch_parent where latch#=197;


ADDR                 LATCH#     LEVEL# NAME                                 HASH
---------------- ---------- ---------- ------------------------------ ----------
0000000060025578        197          8 mapped buffers lru chain         93631960


SQL> select addr,latch#,child#,level#,name,hash from v$latch_children where latch#=197 order by 3;


no rows selected




再看下KFC LRU latch


SQL> select addr,latch#,level#,name,hash from v$latch_parent where latch#=478;


ADDR                 LATCH#     LEVEL# NAME                                 HASH
---------------- ---------- ---------- ------------------------------ ----------
00000000600458C0        478          6 KFC LRU latch                  3390864701




SQL> select addr,latch#,child#,level#,name,hash from v$latch_children where latch#=478 order by 3;


no rows selected


所以,综上,可以_db_block_lru_latches控制simulator lru latch的子latch的个数


8,我们以上述的思路再分析下_deq_ht_child_latches参数的含义
_deq_ht_child_latches                              8                                                  deq ht child latches


SQL> select latch#,name,hash from v$latchname where lower(name) like '%deq%';


    LATCH# NAME                                 HASH
---------- ------------------------------ ----------
       442 AQ deq hash table latch         706044507
       443 AQ dequeue txn counter latch   1724707315
       446 AQ deq log statistics latch     451189647
       447 AQ deq log cmt cbk chunk latch 1639732011




SQL> select addr,latch#,child#,level#,name,hash from v$latch_children where latch#=442 order by 3;


ADDR                 LATCH#     CHILD#     LEVEL# NAME                                 HASH
---------------- ---------- ---------- ---------- ------------------------------ ----------
00000000D31A6238        442          1          4 AQ deq hash table latch         706044507
00000000D31A63A0        442          2          4 AQ deq hash table latch         706044507
00000000D31A6508        442          3          4 AQ deq hash table latch         706044507
00000000D31A6670        442          4          4 AQ deq hash table latch         706044507
00000000D31A67D8        442          5          4 AQ deq hash table latch         706044507
00000000D31A6940        442          6          4 AQ deq hash table latch         706044507
00000000D31A6AA8        442          7          4 AQ deq hash table latch         706044507
00000000D31A6C10        442          8          4 AQ deq hash table latch         706044507


8 rows selected.




SQL> select addr,latch#,child#,level#,name,hash from v$latch_children where latch#=443 order by 3;


no rows selected


SQL> select addr,latch#,child#,level#,name,hash from v$latch_children where latch#=446 order by 3;


no rows selected


SQL> select addr,latch#,child#,level#,name,hash from v$latch_children where latch#=447 order by 3;


no rows selected


9,刚才我们调整了参数_db_block_lru_latches,从原来8变成10,发现还是原来的值,那要是我调小参数值,又会如何呢
老样子,参数_db_block_lru_latches不能调大也不能调小


SQL> alter system set "_db_block_lru_latches"=5 scope=spfile;


System altered.


SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup
ORACLE instance started.


Total System Global Area 2137886720 bytes
Fixed Size                  2215064 bytes
Variable Size            1409287016 bytes
Database Buffers          721420288 bytes
Redo Buffers                4964352 bytes
Database mounted.
Database opened.


NAME_1                                             VALUE_1                                            DESC1
-------------------------------------------------- -------------------------------------------------- --------------------------------------------------
_db_block_lru_latches                              8                                                  number of lru latches

个人简介:


8年oracle从业经验,具备丰富的oracle技能,目前在国内北京某专业oracle服务公司从事高级技术顾问。
   
   服务过的客户:
          中国电信
          中国移动
          中国联通
          中国电通
          国家电网
          四川达州商业银行
          湖南老百姓大药房
          山西省公安厅
          中国邮政
          北京302医院     
          河北廊坊新奥集团公司
  
 项目经验:
           中国电信3G项目AAA系统数据库部署及优化
           中国联通CRM数据库性能优化
           中国移动10086电商平台数据库部署及优化
           湖南老百姓大药房ERR数据库sql优化项目
           四川达州商业银行TCBS核心业务系统数据库模型设计和RAC部署及优化
           四川达州商业银行TCBS核心业务系统后端批处理存储过程功能模块编写及优化
           北京高铁信号监控系统RAC数据库部署及优化
           河南宇通客车数据库性能优化
           中国电信电商平台核心采购模块表模型设计及优化
           中国邮政储蓄系统数据库性能优化及sql优化
           北京302医院数据库迁移实施
           河北廊坊新奥data guard部署及优化
           山西公安厅身份证审计数据库系统故障评估
         
 联系方式:
          手机:18201115468
          qq   :   305076427
          qq微博: wisdomone1
          新浪微博:wisdomone9
          qq群:275813900    
          itpub博客名称:wisdomone1    http://blog.itpub.net/9240380/

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/9240380/viewspace-1820418/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论
提供针对oracle初学者及进阶的数据库培训,欢迎大家咨询: 微信: wisdomone 微信公众号: lovedb 工作经历: 中国普天 北京科蓝 北京云和恩墨 北京神州新桥

注册时间:2008-04-04

  • 博文量
    2189
  • 访问量
    12689917