[20161230]查看父游标中sql语句.txt

[20161230]查看父游标中sql语句.txt

--上午巡检完,无聊,测试使用oradebug下查看sql语句在父游标中的内容.sql语句在执行第一次硬解析时生成父子游标,其中父游标chunk
--中保存sql语句,测试通过oradebug下如何查看:

1.环境:
SCOTT@book> select * from dept where deptno=10;
    DEPTNO DNAME          LOC
---------- -------------- -------------
        10 ACCOUNTING     NEW YORK

--多执行几次,保持sql语句光标在共享池中,确定sql_id= 4xamnunv51w9j.

SYS@book> @ &r/sharepool/shp4 4xamnunv51w9j 0
old  17:  WHERE kglobt03 = '&1'  or kglhdpar='&1' or kglhdadr='&1' or KGLNAHSH= &2
new  17:  WHERE kglobt03 = '4xamnunv51w9j'  or kglhdpar='4xamnunv51w9j' or kglhdadr='4xamnunv51w9j' or KGLNAHSH= 0
TEXT           KGLHDADR         KGLHDPAR         C40                                      KGLOBHD0         KGLOBHD6           KGLOBHS0   KGLOBHS6   KGLOBT16   N0_6_16        N20   KGLNAHSH KGLOBT03        KGLOBT09
-------------- ---------------- ---------------- ---------------------------------------- ---------------- ---------------- ---------- ---------- ---------- --------- ---------- ---------- ------------- ----------
子游标句柄地址 000000007BE4DDB8 000000007D1B5D98 select * from dept where deptno=10       000000007CBCC6D0 000000007BA5D690       4560      12144       3067     19771      19771  911274289 4xamnunv51w9j          0
父游标句柄地址 000000007D1B5D98 000000007D1B5D98 select * from dept where deptno=10       000000007B5E7E88 00                     4720          0          0      4720       4720  911274289 4xamnunv51w9j      65535

--父游标地址=000000007D1B5D98

2.看看范围:
> SELECT * FROM x$ksmsp WHERE TO_NUMBER ('000000007D1B5D98', 'xxxxxxxxxxxxxxxx') between TO_NUMBER(KSMCHPTR, 'xxxxxxxxxxxxxxxx') and TO_NUMBER(KSMCHPTR, 'xxxxxxxxxxxxxxxx')+KSMCHSIZ
ADDR                   INDX    INST_ID   KSMCHIDX   KSMCHDUR KSMCHCOM         KSMCHPTR           KSMCHSIZ KSMCHCLS   KSMCHTYP KSMCHPAR
---------------- ---------- ---------- ---------- ---------- ---------------- ---------------- ---------- -------- ---------- ----------------
00007FFD8A3FB4B8       9505          1          1          1 KGLHD            000000007D1B5D68        560 recr             80 00

--可以确定范围: 0x00007F6F855B1CB0 ,0x00007F6F855B1CB0+560.

--//先看看sql语句转储的内容:
SCOTT@book> select dump('select * from dept where deptno=10',16) from dual ;
DUMP('SELECT*FROMDEPTWHEREDEPTNO=10',16)
--------------------------------------------------------------------------------------------------------------------
Typ=96 Len=34: 73,65,6c,65,63,74,20,2a,20,66,72,6f,6d,20,64,65,70,74,20,77,68,65,72,65,20,64,65,70,74,6e,6f,3d,31,30

--//我使用的cpu是intel系列的,存在大小头问题,在内存中看到的应该4个字节4个字节颠倒.前面4个应该是65,6c,65,73(16进制).
--//BTW: 我的测试oradebug peek最多查询60个字节.
SYS@book> oradebug peek 0x000000007D1B5D98 64
[07D1B5D98, 07D1B5DD8) = 807CBD30 00000000 807CBD30 00000000 7BA5CFD0 00000000 7D1B5EF0 00000000 00010000 10012841 00000001 00000001 00010001 00000002 ...
SYS@book> oradebug peek 0x000000007D1B5D98 60
[07D1B5D98, 07D1B5DD4) = 807CBD30 00000000 807CBD30 00000000 7BA5CFD0 00000000 7D1B5EF0 00000000 00010000 10012841 00000001 00000001 00010001 00000002 00000000

3.继续测试:
SCOTT@book> select 'oradebug peek '|| to_char(TO_NUMBER ('000000007D1B5D98', 'xxxxxxxxxxxxxxxx')+(rownum-1)*60)||' 60;' c40 from dual connect by level<=10;
C40
----------------------------------------
oradebug peek 2098945432 60;
oradebug peek 2098945492 60;
oradebug peek 2098945552 60;
oradebug peek 2098945612 60;
oradebug peek 2098945672 60;
oradebug peek 2098945732 60;
oradebug peek 2098945792 60;
oradebug peek 2098945852 60;
oradebug peek 2098945912 60;
oradebug peek 2098945972 60;
10 rows selected.

--60*9+20=560,修改最好一行oradebug peek 2098945972 20;执行如下:

oradebug setmypid
spool aa.txt
oradebug peek 2098945432 60;
oradebug peek 2098945492 60;
oradebug peek 2098945552 60;
oradebug peek 2098945612 60;
oradebug peek 2098945672 60;
oradebug peek 2098945732 60;
oradebug peek 2098945792 60;
oradebug peek 2098945852 60;
oradebug peek 2098945912 60;
oradebug peek 2098945972 20;
spool off

$ cat aa.txt | grep -i 656c6573
[07D1B5F3C, 07D1B5F78) = 00000053 656C6573 2A207463 6F726620 6564206D 77207470 65726568 70656420 3D6F6E74 00003031 00000000 00000000 00000000 00000000 00000000

--//可以确定偏移量是0x07D1B5F40.
SYS@book> oradebug peek 0x07D1B5F40 60
[07D1B5F40, 07D1B5F7C) = 656C6573 2A207463 6F726620 6564206D 77207470 65726568 70656420 3D6F6E74 00003031 00000000 00000000 00000000 00000000 00000000 00000000

--//7D1B5F40 = 2098945856
--//7D1B5D68 = 2098945384
--//2098945856-2098945384=472
--偏移在472的位置.

$ echo  "656C6573 2A207463 6F726620 6564206D 77207470 65726568 70656420 3D6F6E74 00003031"| xxd -r -p | od -t x4 | cut -c9- | xxd -r -p ;echo
select * from dept where deptno=10
--对比sql语句正好吻合

$ cut -f2 -d= aa.txt | sed 's/ //g'| xxd -r -p | od -t x4 -v | cut -c9- | xxd -r -p  >| aa.bin
$ ls -l aa.bin
-rw-r--r-- 1 oracle oinstall 560 2016-12-30 09:28:32 aa.bin

$ xxd -c 32 aa.bin
0000000: 30bd 7c80 0000 0000 30bd 7c80 0000 0000 d0cf a57b 0000 0000 f05e 1b7d 0000 0000  0.|.....0.|.....邢.{....館.}....
0000020: 0000 0100 4128 0110 0100 0000 0100 0000 0100 0100 0200 0000 0000 0000 0d00 0000  ....A(..........................
0000040: 0000 0100 0000 0000 0000 0000 0000 0000 685f 1b7d 0000 0000 0100 0000 0000 0000  ................h_.}............
0000060: f85d 1b7d 0000 0000 f85d 1b7d 0000 0000 085e 1b7d 0000 0000 085e 1b7d 0000 0000  鴀.}....鴀.}.....^.}.....^.}....
0000080: 7069 2c7d 0000 0000 7069 2c7d 0000 0000 285e 1b7d 0000 0000 285e 1b7d 0000 0000  pi,}....pi,}....(^.}....(^.}....
00000a0: e008 617e 0000 0000 e008 617e 0000 0000 0000 0000 0000 0000 0100 0000 0000 0000  ?a~....?a~....................
00000c0: d574 aa4e 0000 0000 31f1 0000 0000 0000 d85e 1b7d 0000 0000 705e 1b7d 0000 0000  誸狽....1?.....豝.}....p^.}....
00000e0: 705e 1b7d 0000 0000 805e 1b7d 0000 0000 805e 1b7d 0000 0000 0000 0000 0000 0000  p^.}.....^.}.....^.}............
0000100: 68ff 0680 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0300 0000 0100 0000  h?..............................
0000120: 0200 0200 0000 0000 0100 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000  ................................
0000140: 0000 0000 0000 0000 2e00 0000 0000 0000 31f1 5036 0000 0000 5dc4 3114 e7b9 dbbd  ................1馪6....]?.??
0000160: d574 aa4e 31f1 5036 0000 0000 7874 0c1e 0921 2f00 0000 0000 0000 0000 0000 0000  誸狽1馪6....xt...!/.............
0000180: 2300 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 405f 1b7d 0000 0000  #.......................@_.}....
00001a0: 31f1 5036 5300 0000 7365 6c65 6374 202a 2066 726f 6d20 6465 7074 2077 6865 7265  1馪6S...select * from dept where
00001c0: 2064 6570 746e 6f3d 3130 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000   deptno=10......................
00001e0: 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000  ................................
0000200: 0102 0000 008f b380 685d 1b7d 0000 0000 f893 1e7d 0000 0000 3007 8b7d 0000 0000  ........h].}....?.}....0..}....
0000220: 0000 0000 0000 0000 0000 0000 5000 0000                                          ...........

时间: 2024-08-03 14:02:13

[20161230]查看父游标中sql语句.txt的相关文章

20140321]查看大量消耗资源的sql语句.txt

20140321]查看大量消耗资源的sql语句.txt 昨天看Apress.Oracle.Database.12c.Performance.Tuning.Recipes.Dec.2013.pdf,发现P394提高一个 sql语句查看Resource-Intensive SQL in Memory很有意思,做一个记录: Viewing Resource-Intensive SQL in Memory P394 SELECT sql_id, substr(sql_text,1,20) ,disk_r

[20131031]从跟踪文件中抽取sql语句.txt

[20131031]从跟踪文件中抽取sql语句.txt 以前写过利用tkprof顺序抽取执行的sql语句http://space.itpub.net/267265/viewspace-748041但是递归语句没有记录下来. 今天看了一篇blog,记录如下:--说明:我修改2处:dept那行里面的-1原文有错,应该是半角-1.--printf "%s %s %s>>>> %s\n", stmt_count, depth_level, cursor_no, $0--

跟踪oracle中sql语句执行过程及相关知识拓展

select * from v$sqlarea; select * from v$sqlarea where first_load_time>'2010-11-27/09:30:00';         这个方法查询结果每条记录显示一条查询语句,且只能查询sql_text小于1000字符的,多余的会被截断.         改进一下: select * from v$sqlarea where first_load_time>'2010-11-27/09:30:00' and sql_text

Oracle中SQL语句解析的步骤

我们都知道在Oracle中每条SQL语句在执行之前都需要经过解析,这里面又分为软解析和硬解析.那么这两种解析有何不同之处呢?它们又分别是如何进行解析呢?Oracle内部解析的步骤又是如何进行的呢?下面我们就这些话题进行共同探讨. 在Oracle中存在两种类型的SQL语句,一类为DDL语句,他们是从来不会共享使用的,也就是每次执行都需要进行硬解析.还有一类就是DML语句,他们会根据情况选择要么进行硬解析,要么进行软解析.在Oracle 8i OCP教材的023中1-12有说明SQL语句的解析步骤,

[20150705]从AWR抽取有问题的sql语句.txt

[20150705]从AWR抽取有问题的sql语句.txt --闲着没事,写一个脚本从awr数据里面抽取有问题的sql语句,主要我不想看awr报表,而优化80%的问题集中在sql语句,实际上可能更多. --另外我看报表主要集中在9-11点,下午3-5点这些报表,这样可能漏调一些晚上的一些schedule,job等相关sql语句的优化. --注意一定要在环境变量中设置 --NLS_DATA_FORMAT='YYYY/MM/DD HH24:MI:SS' prompt prompt @deltasql

[20150831]中文符号在sql语句.txt

[20150831]中文符号在sql语句.txt --今天在检查代码时发现sql语句中存在全角的等号"=",很明显oracle并没有报错. --实际上itpub上以前有人提到全角","也不会报错. --自己也测试一下: SCOTT@test> @ver1 PORT_STRING                    VERSION        BANNER ------------------------------ -------------- -----

[20150527]跟踪单个sql语句.txt

[20150527]跟踪单个sql语句.txt --11G下可以使用如下脚本跟踪单个sql语句,&1 表示 sql_id.   $ cat sql_trace.sql alter system set events 'sql_trace[SQL:&1] level 12'; host sleep 300 alter system set events 'sql_trace[SQL:&1] off'; --缺点生成的文件在各个用户的trc文件中.

[20121101]tkprof抽取sql语句.txt

[20121101]tkprof抽取sql语句.txt 有时候跟踪分析sql语句,并不是要看里面的递归的执行,或者性能问题.而是要收集跟踪命令的执行序列. 查看tkprof的帮助: Usage: tkprof tracefile outputfile [explain= ] [table= ]               [print= ] [insert= ] [sys= ] [sort= ]   table=schema.tablename   Use 'schema.tablename'

ASP中SQL语句导致的性能问题

问题|性能|语句 今天,修改了一点上次做的办公管理系统中的文件上传的BUG,原因是ASP中SQL语句性能问题导致了RecordSet对象关闭,结果使数据入库失败.对于这个错误,我目前只能这样理解了: SQL语句 select * from TAB_FILES 打开表后,然后调用AddNew方法添加要更新的数据,表面上看没什么问题,当TAB_FILES表中记录相当多时, select * from TAB_FILES 问题就暴露了,所有被选择的数据会写入系统内存缓冲区(实际操作由RecordSet