深入理解shared pool共享池之library cache的library cache lock系列四
本文了解下等待事件library cache lock,进一步理解library cache,之前的文章请见:
深入理解shared pool共享池之library cache的library cache pin系列三
相关图例
为了真观理解library cache pin及library cache lock的联系,有个图:
结论
1,道理同library cache pin一样,诊断library cache lock也要使用v$session及dba_kgllock
2, library cache lock是由于library cache pin所引发的,即后者是原因
因为如果会话想修改或查看对象,必须对对象持锁后获取一个PIN,即先要获取library cache pin,然后才是library cache lock
3, 从DUMP LIBRARY CACHE的结构来看,
可见基于前文:多了lock waiters结构,从LIBRARY CACHE LOCK的含义可见,必须先要获取LIBRARY CACHE PIN,方可获取到LIBRARY CACHE LOCK,现在明显LIBRARY CACHE PIN被其它会话占用,所以获取不到,
只有等待,这样就产生了LIBRARY CACHE LOCK,也就是说只要产生LIBRARY CACHE LOCK,必然存在LIBRARY CACHE PIN,而如果出现LIBRARY CACHE PIN,不一定会出现LIBRARY CACHE LOCK
4,所以在产生LIBRARY CACHE PIN要马上处理,以防在业务高期连锁出现library cache lock,最终把业务拖死
5,当然上述我们只是从原理来分析下library cache pin及library cache lock,可以直接采用如下脚本,直接找到原因(不过你明白了LIBRARY CACHE的原因,会更有助于解决与此相关的故障)
当然你直接通过blocking_session也可以更为真观直接找到引发library cache lock的元凶,直观原因是library cache pin,最后原因是执行存储过程
也可以说明library cache lock不是latch,而是锁lock
SQL> select sid,serial#,saddr,event,blocking_session from v$session where sid in (111,116,121);
SID SERIAL# SADDR EVENT BLOCKING_SESSION
---------- ---------- ---------------- ------------------------------ ----------------
111 101 00000000A4720168 library cache lock 121
116 153 00000000A4726CC0 SQL*Net message from client
121 215 00000000A472D818 library cache pin 116
6,library cache lock和library cache pin一样,不是LATCH,它是LOCK锁
测试
library cache lock的含义:
1,用于管理并发访问library cache
2,pinning一个对象,即会把HEAP加载到内存中,也就是说获取到PIN后,方可把HEAP加载到内存中
3,如果会话想修改或查看对象,必须对对象持锁后获取一个PIN,即先要获取library cache pin,然后才是library cache lock
在上述前文的继续,如果新开一个会话编译存储过程,则会产生library cache lock
SQL> select sid from v$mystat where rownum=1;
SID
----------
111
SQL> alter procedure proc_hard_parse compile;
SQL> select sid,event,p1,p2,p3 from v$session_wait where sid in (116,121,111);
SID EVENT P1 P2 P3
---------- ---------------------------------------------------------------- ---------- ---------- ----------
111 library cache lock 2739958280 2664431712 301
116 SQL*Net message from client 1650815232 1 0
121 library cache pin 2739958280 2663017352 301
--查询与library cache lock相关的LATCH
SQL> select latch#,name from v$latch where lower(name) like '%library cache lock%';
LATCH# NAME
---------- --------------------------------------------------
218 library cache lock
221 library cache lock allocation
--library cache lock LATCH的信息
SQL> select latch#,name from v$latch_children where lower(name) like '%library cache lock%';
LATCH# NAME
---------- ------------------------------
218 library cache lock
218 library cache lock
218 library cache lock
218 library cache lock
218 library cache lock
218 library cache lock
218 library cache lock
218 library cache lock
218 library cache lock
218 library cache lock
218 library cache lock
SQL> select name,parameter1,parameter2,parameter3,wait_class from v$event_name where lower(name) like '%library cache lock%';
NAME PARAMETER1 PARAMETER2 PARAMETER3 WAIT_CLASS
------------------------------ ------------------------------ ------------------------------ ------------------------------ --------------------
library cache lock handle address lock address 100*mode+namespace Concurrency
---解决LIBRARY CACHE LOCK的脚本
---第1步
可见LIBRARY CACHE LOCK及LIBRARY CACHE PIN皆是基于LIBRARY CACHE HANDLE
SQL> select sid,event,p1,p2,p3 from v$session_wait where sid in (116,121,111);
SID EVENT P1 P2 P3
---------- ---------------------------------------------------------------- ---------- ---------- ----------
111 library cache lock 2739958280 2664431712 301 ---library cache lock
116 SQL*Net message from client 1650815232 1 0
121 library cache pin 2739958280 2663017080 301
---第2步,转换上述的P1为16进制
SQL> select to_char('2739958280','xxxxxxxx') from dual;
TO_CHAR('
---------
a3507208
--第3步,传入上述的P1到如下字典,找到等待及持有LIBRARY CACHE LOCK的信息(请注意列:KGLLKMOD及KGLKREQ的2个列,道理同于V$LOCK的REQUEST及LMODE)
SQL> select kgllkuse,kgllkhdl,kgllkmod,kgllkreq,kgllktype from dba_kgllock where kgllkhdl='00000000A3507208' and kgllktype='Lock';
KGLLKUSE KGLLKHDL KGLLKMOD KGLLKREQ KGLL
---------------- ---------------- ---------- ---------- ----
00000000A4720168 00000000A3507208 0 3 Lock --等待library cache lock者
00000000A4726CC0 00000000A3507208 1 0 Lock
00000000A472D818 00000000A3507208 3 0 Lock ---持有library cache lock者
--第4步找到library cache lock的引发者,即library cache pin(关于library cache pin,请见我本文开始的之前的前文)
SQL> select sid,serial#,event from v$session where saddr='00000000A472D818';
SID SERIAL# EVENT
---------- ---------- ------------------------------
121 215 library cache pin
再整合下上述的SQL脚本
当然你直接通过blocking_session也可以更为真观直接找到引发library cache lock的元凶,直观原因是library cache pin,最后原因是执行存储过程
也可以说明library cache lock不是latch,而是锁lock
SQL> select sid,serial#,saddr,event,blocking_session from v$session where sid in (111,116,121);
SID SERIAL# SADDR EVENT BLOCKING_SESSION
---------- ---------- ---------------- ------------------------------ ----------------
111 101 00000000A4720168 library cache lock 121
116 153 00000000A4726CC0 SQL*Net message from client
121 215 00000000A472D818 library cache pin 116
再从library cache bucket这个维度分析下,可见基于前文:多了lock waiters结构,从LIBRARY CACHE LOCK的含义可见,必须先要获取LIBRARY CACHE PIN,方可获取到LIBRARY CACHE LOCK,现在明显LIBRARY CACHE PIN被其它会话占用,所以获取不到,
只有等待,这样就生了LIBRARY CACHE LOCK,也就是说只要产生LIBRARY CACHE LOCK,必然存在LIBRARY CACHE PIN,而如果出现LIBRARY CACHE PIN,不一定会出现LIBRARY CACHE LOCK
BUCKET 59215:
LIBRARY OBJECT HANDLE: handle=a3507208 mtx=0xa3507338(0) lct=33 pct=32 cdp=0
name=SCOTT.PROC_HARD_PARSE
hash=84bc90d61f9452e79e7fe2d54c82e74f timestamp=11-24-2015 02:02:36
namespace=TABL flags=KGHP/TIM/SML/[02000000]
kkkk-dddd-llll=0000-001d-20bf lock=X pin=S latch#=9 hpc=000c hlc=000c
lwt=0xa35072b0[0x9ed00090,0x9ed00090] ltm=0xa35072c0[0xa35072c0,0xa35072c0]
pwt=0xa3507278[0x9eba6d50,0x9eba6d50] ptm=0xa3507288[0xa3507288,0xa3507288]
ref=0xa35072e0[0xa35072e0,0xa35072e0] lnd=0xa35072f8[0xa34de600,0xa34fed28]
DEPENDENCY REFERENCES:
reference latch flags
--------- ----- -------------------
98cf88c8 2 DEP[01] whr=0 timestamp=11-24-2015 02:02:36
LOCK OWNERS:
lock user session count mode flags
-------- -------- -------- ----- ---- ------------------------
9ebc9b28 a472d818 a472d818 1 X [00] --可以关联DBA_KGLLOCK及V$SESSION找到引发LIBRARY CACHE LOCK的直接原凶,即上述的121会话,可见持有排它锁
9eb3d748 a4726cc0 a4726cc0 1 N PNC/[400] --这是个是最终的原凶,因为最初这个会话是持有NULL模式的LOCK锁,即上述的116会话,可见持有NULL锁
9eb3d3b0 a4726cc0 a4726cc0 0 N [4044]
LOCK WAITERS:
lock user session count mode
-------- -------- -------- ----- ----
9ed00060 a4720168 a4720168 0 X
PIN OWNERS:
pin user session lock count mode mask
-------- -------- -------- -------- ----- ---- ----
9eae0b98 a4726cc0 a4726cc0 9eb3d748 3 S 0011
PIN WAITERS:
pin user session lock count mode mask
-------- -------- -------- -------- ----- ---- ----
9eba6d20 a472d818 a472d818 0 0 X 0000
LIBRARY OBJECT: object=9d949488
type=PRCD flags=EXS/LOC[0005] pflags=NST[0001] status=VALD load=0
DEPENDENCIES: count=3 size=16
dependency# table reference handle position flags
----------- -------- --------- -------- -------- -------------------
0 9d94b210 9d94af50 a3a1b6f0 0 DEP[01]
1 9d94b210 9d94afa8 a351ce38 33 DEP[01]
2 9d94b210 9d94b000 a3929db0 0 DEP[01]
READ ONLY DEPENDENCIES: count=1 size=16
dependency# table reference handle flags
----------- -------- --------- -------- -------------------
0 9d9288d0 9d9285e8 a34fa2c8 /ROD[20]
ACCESSES: count=1 size=16
dependency# types
----------- -----
1 0009
TRANSLATIONS: count=1 size=16
original final
-------- --------
a351ce38 a351ce38
DATA BLOCKS:
data# heap pointer status pins change whr alloc(K) size(K)
----- -------- -------- --------- ---- ------ --- -------- --------
0 a3507148 9d9495a0 I/P/A/-/- 0 NONE 00 0.37 1.09
2 9d9497a0 977456b0 I/-/A/-/- 0 NONE 00 13.27 16.00
4 9d928540 97b67850 I/P/A/-/- 1 NONE 00 2.26 4.00
BUCKET 59215 total object count=1
深入理解shared pool共享池之library cache的library cache lock系列四的更多相关文章
- 深入理解shared pool共享池之library cache系列二
背景 继续上文:深入理解shared pool共享池之library cache系列一,学习library cache数据结构,本文主要学习library cache object(lco)的数据结构 ...
- 深入理解shared pool共享池之library cache的library cache pin系列三
关于library cache相关的LATCH非常多,名称差不多,我相信一些人对这些概念还是有些晕,我之前也有些晕,希望此文可以对这些概念有个更为清晰的理解,本文主要学习library cache p ...
- 深入理解shared pool共享池之library cache系列一
结论 1,oradebug dump library_cache不同级别dump的library cache内容及粒度会有所区别,具体见测试开始部分2,本文测示基于oradebug dump libr ...
- shared pool详解
共享池shared pool的概念用户提交的命令:解析.执行用户命令的解析解析的过程是一个相当复杂的过程,它要考虑各种可能的异常情况比如SQL语句涉及到的对象不存在.提交的用户没有权限等等而且还需要考 ...
- Oracle数据库体系结构-Shared Pool
Oracle数据库简单介绍 对象关系型数据库 重点:一致性+性能 一致性优于性能 处理模型:C/S模型 Client:用户和用户进程 Server:服务器进程,实例,数据库本身 ...
- [转载】——故障排除:Shared Pool优化和Library Cache Latch冲突优化 (文档 ID 1523934.1)
原文链接:https://support.oracle.com/epmos/faces/DocumentDisplay?_adf.ctrlstate=23w4l35u5_4&id=152393 ...
- [20190319]shared pool latch与library cache latch的简单探究.txt
[20190319]shared pool latch与library cache latch的简单探究.txt --//昨天看Oracle DBA手记3:数据库性能优化与内部原理解析.pdf 电子书 ...
- Oracle Shared Pool之Library Cache
1. Shared Pool组成 Shared Pool由许多区间(Extent)组成,这些区间又由多个连续的内存块(Chunk)组成,这些内存块大小不一.从逻辑功能角度,Shared pool主要包 ...
- 关于shared pool的深入探讨(二)【转载】
关于shared pool的深入探讨(二) 作者:eygle |English [转载时请标明出处和作者信息]|[恩墨学院 OCM培训传DBA成功之道]链接:http://www.eygle.co ...
随机推荐
- 动态规划(DP计数):HDU 5121 Just A Mistake
As we all know, Matt is an outstanding contestant in ACM-ICPC. Graph problems are his favorite.Once, ...
- 检测Office是否安装以及获取安装 路径 及安装版本 QQ,迅雷,旺旺 C#代码
#region 检测Office是否安装 ///<summary> /// 检测是否安装office ///</summary> ///<param name=" ...
- 遍历form表单
//表单 var form = new Ext.form.FormPanel({ //创建表单面板 labelAlign: 'center', //水平对齐方式 layout: 'form', //布 ...
- 如何避免jQuery库和其他库的冲突
默认情形:jQuery用$作为自身的快捷方式 1. jQuery库在其他库之后导入 (1)方法:使用jQuery.noConflict()函数将变量$的控制权转移给其他库 (2)操作: (a)在js代 ...
- visual studio 资源视图 空白 解决方案
visual studio 资源视图打开后显示空白的解决方案步骤: 在解决方案view下,右键点击工程 1 unload projects 完成第一步后仍然在解决方案view下,右键点击工程 2 re ...
- leecode 排列的学习
前面写过3个排列.这里再写一次. 1.全部都不重复https://oj.leetcode.com/problems/permutations/ (使用交换法)只是本人对c++ stl不熟,不会把排列结 ...
- poj 2451 Uyuw's Concert(半平面交)
Uyuw's Concert Time Limit: 6000MS Memory Limit: 65536K Total Submissions: 8580 Accepted: 3227 De ...
- mv、umask、chattr、lsattr命令
mv命令行,即move 将文件移动到目录下 对文件或目录重命名 umask chattr 设置文件或目录的隐藏属性 lsattr显示文件或目录的隐藏属性 ls mv 1.txt aa ls cd aa ...
- Why should i use url.openStream instead of of url.getContent?
I would like to retrieve the content of a url. Similar to pythons: html_content = urllib.urlopen(&qu ...
- Android——C语言、JNI与低层调用
JNI java native interface c的基本数据类型 int:32位,能表示的数字是2的32次方个 最高位用来表示符号位,那么还剩下31位可以表示数值,所以能表示的数字就是2的31次方 ...