ITPub博客

首页 > 数据库 > Oracle > [20241113]建立显示某个内存段的通用脚本disp_addr.sh.txt

[20241113]建立显示某个内存段的通用脚本disp_addr.sh.txt

原创 Oracle 作者:lfree 时间:2024-11-16 20:50:38 0 删除 编辑

[20241113]建立显示某个内存段的通用脚本disp_addr.sh.txt

--//该工具仅仅建议在测试环境学习使用。

$ cat disp_addr.sh
#/bin/bash
# display address information
# arg1=address arg2=offset arg3=length arg4=format

offset=${2:-0}
length=${3:-8}
format=${4-wx}

if [ "$format" == "s" ] ; then
        len=1
fi
if [ "$format" == "S" ] ; then
        format="s"
fi

gdb -q -batch -p $(pgrep -f ora_mmon_${ORACLE_SID}) -ex "x/${length}${format} 0x${1}+0x${offset}" -ex "quit" |  grep "^0x" | grep -v "^0x0"

--//简单介绍正常wx格式显示。如果以字符串输出,输入s(小写)时,长度等于1.输入S(大写),改成小写,不修改length值。

SCOTT@book01p> select * from dept where deptno=40;
    DEPTNO DNAME                          LOC
---------- ------------------------------ -------------
        40 OPERATIONS                     BOSTON

SCOTT@book01p> @ hash
HASH_VALUE SQL_ID        CHILD_NUMBER KGL_BUCKET PLAN_HASH_VALUE HASH_HEX   SQL_EXEC_START      SQL_EXEC_ID
---------- ------------- ------------ ---------- --------------- ---------- ------------------- -----------
3912471479 14ymr4znm74xr            0     103351      2852011669  e93393b7  2024-11-14 09:18:39    16777216

SYS@book> @ sharepool/shp4p 14ymr4znm74xr 0
SYS@book> @ pr
==============================
HANDLE_TYPE                   : parent handle address
KGLHDADR                      : 0000000062B283D0
KGLHDPAR                      : 0000000062B283D0
C40                           : select * from dept where deptno=40
KGLHDLMD                      : 0
KGLHDPMD                      : 0
KGLHDIVC                      : 0
KGLOBHD0                      : 0000000062B28210
KGLOBHD6                      : 00
KGLOBHS0                      : 4064
KGLOBHS6                      : 0
KGLOBT16                      : 0
N0_6_16                       : 4064
N20                           : 4064
KGLNAHSH                      : 3912471479
KGLOBT03                      : 14ymr4znm74xr
KGLOBT09                      : 65535
PL/SQL procedure successfully completed.
--//KGLHDPAR : 0000000062B283D0

$ ./disp_addr.sh 0000000062B283D0 1c8 1 s
0x62b28598:     "select * from dept where deptno=40"

--//如果不知道偏移可以这样写。
SYS@book> @ fchaz 0000000062B283D0
LOC KSMCHPTR           KSMCHIDX   KSMCHDUR KSMCHCOM           KSMCHSIZ KSMCHCLS   KSMCHTYP KSMCHPAR         KSMCHPTR_BEGIN   KSMCHPTR_END+1
--- ---------------- ---------- ---------- ---------------- ---------- -------- ---------- ---------------- ---------------- -----------------
SGA 0000000062B283A0          1          1 KGLHD                   816 recr             80 00               0000000062B283A0 0000000062B286D0
--//该chunk占用818字节。

$ ./disp_addr.sh 0000000062B283D0 0 816 S | grep -i select
0x62b28598:     "select * from dept where deptno=40"

--//0x62b28598-0x0000000062B283D0 = 0x1c8,偏移在0x1c8位置。
--//带入816越界没有问题。

--//前面@hash的输出KGL_BUCKET=103351
SYS@book> oradebug setmypid
Statement processed.
SYS@book> oradebug dump library_cache 4;
Statement processed.
SYS@book> @ t
TRACEFILE
--------------------------------------------------------------------------------
/u01/app/oracle/diag/rdbms/book/book/trace/book_ora_3719.trc

$ grep 103351 /u01/app/oracle/diag/rdbms/book/book/trace/book_ora_3719.trc
Bucket: #=103351 Mutex=0x7309f5c0(639950127104, 11, 0, 6)
--//mutex地址在0x7309f5c0。

$ ./disp_addr.sh 7309f5c0 0 6 wx
0x7309f5c0:     0x00000000      0x00000000      0x0000000b      0x00000000
0x7309f5d0:     0x000193b7      0x00000000
--//gets=0xb.
--//0x000193b7 = 103351,等于KGL_BUCKET值。

$ ./disp_addr.sh 7309f5b0 0 8 wx
0x7309f5b0:     0x62b283d0      0x00000000      0x62b283d0      0x00000000
0x7309f5c0:     0x00000000      0x00000000      0x0000000c      0x00000000
--//0x62b283d0就是该sql语句父游标句柄地址。

SCOTT@book01p> select * from dept where deptno=40;
    DEPTNO DNAME                          LOC
---------- ------------------------------ -------------
        40 OPERATIONS                     BOSTON

$ ./disp_addr.sh 7309f5b0 0 12 wx
0x7309f5b0:     0x62b283d0      0x00000000      0x62b283d0      0x00000000
0x7309f5c0:     0x00000000      0x00000000      0x0000000d      0x00000000
0x7309f5d0:     0x000193b7      0x00000000      0x62820b38      0x00000000
--//gets=0xd.增加1.
--//每执行1次查看1次。

$ ./disp_addr.sh 7309f5b0 0 12 wx
0x7309f5b0:     0x62b283d0      0x00000000      0x62b283d0      0x00000000
0x7309f5c0:     0x00000000      0x00000000      0x0000000e      0x00000000
0x7309f5d0:     0x000193b7      0x00000000      0x62820b38      0x00000000

$ ./disp_addr.sh 7309f5b0 0 12
0x7309f5b0:     0x62b283d0      0x00000000      0x62b283d0      0x00000000
0x7309f5c0:     0x00000000      0x00000000      0x0000000e      0x00000000
0x7309f5d0:     0x000193b7      0x00000000      0x62820b38      0x00000000
--//光标缓存后gets不在增加。

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

请登录后发表评论 登录
全部评论
熟悉oracle相关技术,擅长sql优化,rman备份与恢复,熟悉linux shell编程。

注册时间:2008-01-03

  • 博文量
    4006
  • 访问量
    7969562