首页 > 其他分享 >[20241108]跟踪library cache lock library cache pin使用gdb(11g)3.txt

[20241108]跟踪library cache lock library cache pin使用gdb(11g)3.txt

时间:2024-11-08 20:45:59浏览次数:1  
标签:11g handle kgllkal -- lock cache library mode address

[20241108]跟踪library cache lock library cache pin使用gdb(11g)3.txt

--//前一段时间写的使用gdb跟踪library cache lock/library cache pin的脚本。

--//我看过以前的笔记,当时测试过链接https://nenadnoveljic.com/blog/library-cache-lock-debugger/,我的测试在11g是失败.
--//今天有空再次尝试,确实不成功,不过有了前面测试的经验,可以很容易写成11g的gdb监测脚本.
--//前几天完成了11g下的脚本,有一个小问题,不能获取lock address,今天尝试完成它.

--//通过调用kglGetSO返回lock address/pin address.

1.环境:
SCOTT@book> @ver1
PORT_STRING                    VERSION        BANNER
------------------------------ -------------- --------------------------------------------------------------------------------
x86_64/Linux 2.4.xx            11.2.0.4.0     Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production

2.测试:
--//session 1:
--//执行如下语句多次。
SCOTT@book> select * from dept where deptno=20;
    DEPTNO DNAME          LOC
---------- -------------- -------------
        20 RESEARCH       DALLAS

SCOTT@book> @ hash
HASH_VALUE SQL_ID        CHILD_NUMBER KGL_BUCKET PLAN_HASH_VALUE HASH_HEX   SQL_EXEC_START      SQL_EXEC_ID
---------- ------------- ------------ ---------- --------------- ---------- ------------------- -----------
  95129850 80baj2c2ur47u            0     102650      2852011669   5ab90fa  2024-11-08 08:59:46    16777220

--//session 2:
SYS@book> @ sharepool/shp4 80baj2c2ur47u 0
HANDLE_TYPE            KGLHDADR         KGLHDPAR         C40                                        KGLHDLMD   KGLHDPMD   KGLHDIVC KGLOBHD0         KGLOBHD6           KGLOBHS0   KGLOBHS6   KGLOBT16   N0_6_16        N20   KGLNAHSH KGLOBT03        KGLOBT09
---------------------- ---------------- ---------------- ---------------------------------------- ---------- ---------- ---------- ---------------- ---------------- ---------- ---------- ---------- --------- ---------- ---------- ------------- ----------
child handle address   000000007D927640 000000007DB40C60 select * from dept where deptno=20                1          0          0 000000007D3CC960 000000007CAA5948       4528      12144       3067     19739      19739   95129850 80baj2c2ur47u          0
parent handle address  000000007DB40C60 000000007DB40C60 select * from dept where deptno=20                1          0          0 000000007C6565D8 00                     4720          0          0      4720       4720   95129850 80baj2c2ur47u      65535

SYS@book> column KGLNAOBJ format a40
SYS@book> select KGLLKSNM sid ,KGLLKMOD,KGLLKREQ,KGLNAOBJ,KGLLKHDL,KGLLKADR,KGLLKUSE,KGLLKSES from x$kgllk where KGLNAOBJ='select * from dept where deptno=20';
       SID   KGLLKMOD   KGLLKREQ KGLNAOBJ                                 KGLLKHDL         KGLLKADR         KGLLKUSE         KGLLKSES
---------- ---------- ---------- ---------------------------------------- ---------------- ---------------- ---------------- ----------------
         1          1          0 select * from dept where deptno=20       000000007D927640 000000007DAF9380 0000000085C77E38 0000000085C77E38
         1          1          0 select * from dept where deptno=20       000000007DB40C60 000000007D7182E0 0000000085C77E38 0000000085C77E38
--//KGLLKHDL 对应 父子游标的句柄地址,KGLLKADR表示lock地址。

----//session 1,退出重新登录,因为会话光标已经换成,实际上测试前可以设置session_cached_cursors,这样每次都是软解析.
SCOTT@book> alter session set session_cached_cursors=0;
Session altered.

SCOTT@book> @ spid
==============================
SID                           : 1
SERIAL#                       : 1811
PROCESS                       : 19892
SERVER                        : DEDICATED
SPID                          : 19893
PID                           : 24
P_SERIAL#                     : 137
KILL_COMMAND                  : alter system kill session '1,1811' immediate;
PL/SQL procedure successfully completed.
--//我的环境仅仅个人使用,重新登录sid还是1.

--//window 1:
$ cat lkpn11g.gdb
set pagination off
set print repeats 0
set print elements 0
set logging file /tmp/lkpn.log
set logging overwrite on
set logging on
set $lk  = 0
set $pn  = 0
set $lock  = 0

#break kgllkal if $rdx==3
#break kgllkal if ( $rdx==3 && $rsi==0x00000000670C9E58 )
#break kgllkal if $rsi==0x00000000670C9E58
break kgllkal
commands
 silent
 printf "kgllkal count %02d -- handle address: %016x, mode: %d ", ++$lk ,$rsi ,$rdx
 echo kglnaobj address:
 x/s $rsi+0x1a8
 c
 end

#break kglpnal if $rcx==3
break kglpnal
commands
 silent
 printf "kglpnal count %02d -- handle address: %016x, mode: %d ", ++$pn ,$rsi ,$rdx
 echo kglnaobj address:
 x/s $rsi+0x1a8
 c
 end

break kglGetSO
commands
 silent
 finish
 end

$ rlgdb -f -p 19893 -x lkpn11g.gdb
...
0x000000379a00da70 in __read_nocancel () from /lib64/libpthread.so.0
Breakpoint 1 at 0x983da94
Breakpoint 2 at 0x9839f5c
Breakpoint 3 at 0x9845840

--//session 1:
SCOTT@book> select * from dept where deptno=20;
--//挂起!!

(gdb) c
Continuing.
kgllkal count 01 -- handle address: 000000007db40c60, mode: 1 kglnaobj address:0x7db40e08:       "select * from dept where deptno=20"
0x000000000983db73 in kgllkal ()

(gdb) info regi
rax            0x7c174e28       2081902120
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
rbx            0x60004668       1610630760
rcx            0x99d6510        161309968
rdx            0x7c174e28       2081902120
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
rsi            0xc0f1b58        202316632
rdi            0x7d63f408       2103702536
rbp            0x7ffff3af33b0   0x7ffff3af33b0
rsp            0x7ffff3af3300   0x7ffff3af3300
r8             0x14     20
r9             0x0      0
r10            0xea0    3744
r11            0x3      3
r12            0xc0cc9e0        202164704
r13            0x7db40c60       2108951648
r14            0x1      1
r15            0x7ffff3af39e0   140737281735136
rip            0x983db73        0x983db73 <kgllkal+227>
eflags         0x246    [ PF ZF IF ]
cs             0x33     51
ss             0x2b     43
ds             0x0      0
es             0x0      0
fs             0x0      0
gs             0x0      0
fctrl          0x27f    639
fstat          0x420    1056
ftag           0xffff   65535
fiseg          0x0      0
fioff          0x961e00e        157409294
foseg          0x7fff   32767
fooff          0xf3af4160       -206618272
fop            0x0      0
mxcsr          0x1fa0   [ PE IM DM ZM OM UM PM ]
(gdb) c
Continuing.
kgllkal count 02 -- handle address: 000000007d927640, mode: 1 kglnaobj address:0x7d9277e8:       ""
0x000000000983db73 in kgllkal ()
(gdb) c
Continuing.

--//session 2:
SYS@book> select KGLLKSNM sid ,KGLLKMOD,KGLLKREQ,KGLNAOBJ,KGLLKHDL,KGLLKADR,KGLLKUSE,KGLLKSES from x$kgllk where KGLNAOBJ='select * from dept where deptno=20';
       SID   KGLLKMOD   KGLLKREQ KGLNAOBJ                                 KGLLKHDL         KGLLKADR         KGLLKUSE         KGLLKSES
---------- ---------- ---------- ---------------------------------------- ---------------- ---------------- ---------------- ----------------
         1          1          0 select * from dept where deptno=20       000000007D927640 000000007D63F7E8 0000000085C77E38 0000000085C77E38
         1          1          0 select * from dept where deptno=20       000000007DB40C60 000000007C174E28 0000000085C77E38 0000000085C77E38
--//注意看rax=0x7c174e28, 与KGLLKHDL=000000007DB40C60(父游标句柄)那行KGLLKADR=000000007C174E28相互对应。也就是返回后寄
--//存器rax的值就是返回lock address。好像rdx也能对上.
--//这样就可以知道调用kgllkal,再调用kglGetSO返回的地址是0x000000000983db73,在此设置断点,查看相应寄存器就可以知道lock address。
--//这样gdb脚本改写如下:
$ cat lkpn11g.gdb
set pagination off
#set print repeats 0
#set print elements 0
set logging file /tmp/lkpn.log
set logging overwrite on
set logging on
set $lk  = 0
set $pn  = 0
set $lock  = 0

#break kgllkal if $rdx==3
#break kgllkal if ( $rdx==3 && $rsi==0x00000000670C9E58 )
#break kgllkal if $rsi==0x00000000670C9E58
break kgllkal
commands
 silent
 printf "kgllkal count %02d -- handle address: %016x, mode: %d ", ++$lk ,$rsi ,$rdx
 echo kglnaobj address:
 x/s $rsi+0x1a8
 c
 end

#break kglpnal if $rcx==3
break kglpnal
commands
 silent
 printf "kglpnal count %02d -- handle address: %016x, mode: %d ", ++$pn ,$rsi ,$rdx
 echo kglnaobj address:
 x/s $rsi+0x1a8
 c
 end

#break kglGetSO
#commands
# silent
# finish
# end

break *0x000000000983db73
commands
silent
printf "kgllkal kglGetS0 lock address : %016x\n", $rax
c
end

--//重复测试:
--//session 2:
SYS@book> select KGLLKSNM sid ,KGLLKMOD,KGLLKREQ,KGLNAOBJ,KGLLKHDL,KGLLKADR,KGLLKUSE,KGLLKSES from x$kgllk where KGLNAOBJ='select * from dept where deptno=20';
       SID   KGLLKMOD   KGLLKREQ KGLNAOBJ                                 KGLLKHDL         KGLLKADR         KGLLKUSE         KGLLKSES
---------- ---------- ---------- ---------------------------------------- ---------------- ---------------- ---------------- ----------------
         1          1          0 select * from dept where deptno=20       000000007D927640 000000007D63F7E8 0000000085C77E38 0000000085C77E38
         1          1          0 select * from dept where deptno=20       000000007DB40C60 000000007C174E28 0000000085C77E38 0000000085C77E38

--//window 1:
--//退出gdb界面,重新执行:
$ rlgdb -f -p 19893 -x lkpn11g.gdb
0x000000379a00da70 in __read_nocancel () from /lib64/libpthread.so.0
Breakpoint 1 at 0x983da94
Breakpoint 2 at 0x9839f5c
Breakpoint 3 at 0x983db73
(gdb) c
Continuing.
kgllkal count 01 -- handle address: 000000007db40c60, mode: 1 kglnaobj address:0x7db40e08:       "select * from dept where deptno=20"
kglGetS0 lock address : 000000007c174e28
kgllkal count 02 -- handle address: 000000007d927640, mode: 1 kglnaobj address:0x7d9277e8:       ""
kglGetS0 lock address : 000000007d63f7e8
--//完全能对上.剩下定位library cache pin address.实际上如法炮制.

--//注解 lkpn11g.gdb脚本的break kgllkal段落.
set logging file /tmp/lkpn.log
set logging overwrite on
set logging on
set $lk  = 0
set $pn  = 0
set $lock  = 0

#break kgllkal if $rdx==3
#break kgllkal if ( $rdx==3 && $rsi==0x00000000670C9E58 )
#break kgllkal if $rsi==0x00000000670C9E58
#break kgllkal
#commands
# silent
# printf "kgllkal count %02d -- handle address: %016x, mode: %d ", ++$lk ,$rsi ,$rdx
# echo kglnaobj address:
# x/s $rsi+0x1a8
# c
# end

#break kglpnal if $rcx==3
break kglpnal
commands
 silent
 printf "kglpnal count %02d -- handle address: %016x, mode: %d ", ++$pn ,$rsi ,$rdx
 echo kglnaobj address:
 x/s $rsi+0x1a8
 c
 end

break kglGetSO
commands
 silent
 finish
 end

--//session 1:
SCOTT@book> select * from dept where deptno=60;


--//window 1:
--//退出gdb界面,重新执行:

(gdb) c
Continuing.
0x000000000983db73 in kgllkal ()
(gdb) c
Continuing.
0x000000000984175e in kglllal ()
(gdb) c
Continuing.
kglpnal count 01 -- handle address: 000000007c53b830, mode: 2 kglnaobj address:0x7c53b9d8:       "select * from dept where deptno=60"
0x000000000983a048 in kglpnal ()
--//这样就可以知道调用kglpnal,再调用kglGetSO返回的地址是0x000000000983a048,在此设置断点,查看相应寄存器就可以知道lock address。
--//注意一定要对应kglpna调用返回的值,前面2个不是.

$ cat  lkpn11g.gdb
set pagination off
#set print repeats 0
#set print elements 0
set logging file /tmp/lkpn.log
set logging overwrite on
set logging on
set $lk  = 0
set $pn  = 0
set $lock  = 0

#break kgllkal if $rdx==3
#break kgllkal if ( $rdx==3 && $rsi==0x00000000670C9E58 )
#break kgllkal if $rsi==0x00000000670C9E58
break kgllkal
commands
 silent
 printf "kgllkal count %02d -- handle address: %016x, mode: %d ", ++$lk ,$rsi ,$rdx
 echo kglnaobj address:
 x/s $rsi+0x1a8
 c
 end

#break kglpnal if $rcx==3
break kglpnal
commands
 silent
 printf "kglpnal count %02d -- handle address: %016x, mode: %d ", ++$pn ,$rsi ,$rdx
 echo kglnaobj address:
 x/s $rsi+0x1a8
 c
 end

#break kglGetSO
#commands
# silent
# finish
# end

break *0x000000000983db73
commands
silent
printf "kglGetS0 return lock address : %016x %016x\n", $rax,$rdx
c
end

break *0x000000000983a048
commands
 silent
 printf "kglGetS0 return pin address : %016x %016x\n", $rax,$rdx
 c
end


--//session 1:
SCOTT@book> select * from dept where deptno=32;
no rows selected

--//window 1:
--//退出gdb界面,重新执行:
Breakpoint 1 at 0x983da94
Breakpoint 2 at 0x9839f5c
Breakpoint 3 at 0x983db73
Breakpoint 4 at 0x983a048
(gdb) c
Continuing.
kgllkal count 01 -- handle address: 000000007bea0990, mode: 1 kglnaobj address:0x7bea0b38:       "select * from dept where deptno=32"
kglGetS0 return lock address : 000000007c175128 000000007c175128
kglpnal count 01 -- handle address: 000000007bea0990, mode: 2 kglnaobj address:0x7bea0b38:       "select * from dept where deptno=32"
kglGetS0 return pin address : 000000007c175228 000000007c175228
kgllkal count 02 -- handle address: 000000007dbb0788, mode: 2 kglnaobj address:0x7dbb0930:       "bookSYS"
kglGetS0 return lock address : 000000007c174e28 000000007c174e28
kgllkal count 03 -- handle address: 000000007c3e3ba8, mode: 2 kglnaobj address:0x7c3e3d50:       "c40e5b0d7f1b5ad0$BUILD$"
kglGetS0 return lock address : 000000007c175228 000000007c175228
kgllkal count 04 -- handle address: 000000007cebdcb0, mode: 1 kglnaobj address:0x7cebde58:       ""
kglGetS0 return lock address : 000000007d63f7e8 000000007d63f7e8
kglpnal count 02 -- handle address: 000000007cebdcb0, mode: 3 kglnaobj address:0x7cebde58:       ""
kglGetS0 return pin address : 000000007c174e28 000000007c174e28
kgllkal count 05 -- handle address: 000000007dbb0788, mode: 2 kglnaobj address:0x7dbb0930:       "bookSYS"
kglGetS0 return lock address : 000000007c175528 000000007c175528
kgllkal count 06 -- handle address: 000000007d932218, mode: 1 kglnaobj address:0x7d9323c0:       "23bc01efc31eccb6c40e5b0d7f1b5ad0Child:0"
kglGetS0 return lock address : 000000007c5772e0 000000007c5772e0
kglpnal count 03 -- handle address: 000000007d932218, mode: 3 kglnaobj address:0x7d9323c0:       "23bc01efc31eccb6c40e5b0d7f1b5ad0Child:0"
kglGetS0 return pin address : 000000007c5773e0 000000007c5773e0
kgllkal count 07 -- handle address: 000000007d1f57b8, mode: 1 kglnaobj address:0x7d1f5960:       "SCOTT"
kglGetS0 return lock address : 000000007c5772e0 000000007c5772e0
kgllkal count 08 -- handle address: 000000007dbb0788, mode: 2 kglnaobj address:0x7dbb0930:       "bookSYS"
kglGetS0 return lock address : 000000007c174e28 000000007c174e28
kgllkal count 09 -- handle address: 000000007d065910, mode: 2 kglnaobj address:0x7d065ab8:       "DEPTSCOTT"
kglGetS0 return lock address : 000000007c175528 000000007c175528
kglpnal count 04 -- handle address: 000000007d065910, mode: 2 kglnaobj address:0x7d065ab8:       "DEPTSCOTT"
kglGetS0 return pin address : 000000007c5773e0 000000007c5773e0

SYS@book> select * from x$kglpn where KGLPNSID=1;
no rows selected

--//pin address已经释放,另外写一篇验证自己的测试结果是否正确。.

标签:11g,handle,kgllkal,--,lock,cache,library,mode,address
From: https://www.cnblogs.com/lfree/p/18535914

相关文章

  • [20241107]nocache的编译.txt
    [20241107]nocache的编译.txt--//原来的测试环境不存在,需要建立nocache工具了解文件缓存情况,学习OS相关知识。--//实际上linux对这些工具从应用角度讲不重要,如果有用,linux实用程序里面应该包含类似工具。可惜一直不提供。--//一般这类安装,我都会写安装笔记,我看了以前的安装笔记,重......
  • zlibrary镜像网址入口,Zlibray最新官方客户端
    Z-Library(也被称为Z-Lib)是一个在线的、开源的、免费的数字图书馆项目,旨在提供各种书籍、文章、科学论文、杂志、漫画等资源的访问。该项目成立于2009年,至今已经收录了超过10,000,000册书籍和80,000,000篇文章。zlibrary电脑客户端/安卓appzlibrary(windows/mac/安卓/ipad)安装包......
  • Oracle10g / oracle11g 安装过程中的常见错误解决办法-【20241118】
    一、oracle10g安装1、在ORACLE10g安装准备的过程中:缺少libXp.so.6依赖上网搜过不少文章,但是都不是很好的解决我自己摸索出一个解决方法:在RHEL5的安装盘中找到libXp-1.0.0-8.i386.rpm,进行安装后,便可解决。2、在ORACLE10g安装过程中Xlib:connectionto......
  • Z-Library入口网站/最新官方国内可用地址(2024持续更新)
    Z-Library,作为全球最大的数字图书馆之一,提供了一个丰富的知识资源库,包括大量的电子书和学术文章。以下是对Z-Library的详细介绍和一些实用的信息。Z-Library数字图书馆简介藏书量:Z-Library拥有超过9,826,996本电子书和84,837,646篇期刊文章,覆盖了从文学、理工学科到人文艺术......
  • oracle11g 常用基本参数优化设置
    1、进程及会话数进程默认150,会话默认是247;查看进程及会话数showparameterprocess;showparametersessions;2、修改进程及会话数altersystemsetprocesses=1250scope=spfile;altersystemsetsessions=1380scope=spfile;SQL>altersystemsetprocesses=1250......
  • Centos7.8静默安装企业版Oracle11g和创建实例
    1、安装环境准备:A、系统版本和oracle11g企业版安装软件压缩包:[root@dbprimary07~]#cat/etc/redhat-releaseCentOSLinuxrelease7.8.2003(Core)[root@dbprimary07~]#uname-aLinuxdbprimary073.10.0-1127.el7.x86_64#1SMPTueMar3123:36:51UTC2020x86_64x......
  • oracle11g启动过程中加载配置文件
    oracle指定配置文件启动,要是不指定配置文件启动的话默认找的参数文件顺序如下:在oracle11g中oracle启动过程中默认会加载相应的配置文件来启动oracle服务。检查参数文件有两个,一个是spfile<ORACLE_SID>.ora文件,另一个是inti<ORACLE_SID>.ora文件。oracle软件服务安装完成后......
  • [20241105]跟踪library cache lock library cache pin使用gdb(11g)2.txt
    [20241105]跟踪librarycachelocklibrarycachepin使用gdb(11g)2.txt--//前一段时间写的使用gdb跟踪librarycachelock/librarycachepin的脚本。--//我看过以前的笔记,当时测试过链接https://nenadnoveljic.com/blog/library-cache-lock-debugger/,我的测试在11g是失败.--//......
  • 通俗易懂的KVcache图解
    在分享之前先提出三个问题:1.为什么KVCache不保存Q2.KVCache如何减少计算量3.为什么模型回答的长度不会影响回答速度?本文将带着这3个问题来详解KVcacheKVcache是什么kvcache是指一种用于提升大模型推理性能的技术,通过缓存注意力机制中的键值(Key-Value)对来减少冗余......
  • zlibrary中文版入口及电子书客户端/app(2024更新)
    Z-library是一个全球范围内庞大的数字图书馆之一,其藏书量非常丰富。截至最新数据,Z-library共收录了超过9,826,996册电子书以及84,837,646篇学术期刊文章。这个数字图书馆覆盖了从经典文学巨著到前沿理工学科,从人文艺术瑰宝到专业学术论文的广泛领域,几乎能够满足每一位求知者的阅读......