[20150803]無法通過sql_id找到sql語句2.txt

lfree發表於2015-08-03

[20150803]無法通過sql_id找到sql語句2.txt

--前一陣子,在做優化時遇到1個無法通過sql_id找到sql語句的情況:
http://blog.itpub.net/267265/viewspace-1749265/

--就是因為共享池太小,執行次數少,沒到取樣時間,已經從共享池清除。

--實際上還有容易被忽略的情況是lob欄位。通過例子來說明:以前遇到等待事件enq HW - contention時也遇到過:
http://blog.itpub.net/267265/viewspace-1107524/

1.建立測試環境:
SCOTT@test01p> @ver1
PORT_STRING                    VERSION        BANNER                                                                               CON_ID
------------------------------ -------------- -------------------------------------------------------------------------------- ----------
IBMPC/WIN_NT64-9.1.0           12.1.0.1.0     Oracle Database 12c Enterprise Edition Release 12.1.0.1.0 - 64bit Production              0

SCOTT@test01p> create table t (id number , text clob);
Table created.

SCOTT@test01p> insert into t values (1,'aaa');
1 row created.

SCOTT@test01p> commit ;
Commit complete.

SCOTT@test01p> select rowid,t.* from t;
ROWID                      ID TEXT
------------------ ---------- -----------------------------
AAAX/SAAJAAAATeAAA          1 aaa

--執行多次。
SCOTT@test01p> @rowid AAAX/SAAJAAAATeAAA
    OBJECT       FILE      BLOCK        ROW DBA                  TEXT
---------- ---------- ---------- ---------- -------------------- ----------------------------------------
     98258          9       1246          0 9,1246               alter system dump datafile 9 block 1246

SCOTT@test01p> @10to16 98258
10 to 16 HEX   REVERSE16
-------------- ------------------
0000000017fd2 0xd27f0100

--17fd2表示的是object_id.

SCOTT@test01p> @spid
       SID    SERIAL# SPID   C50
---------- ---------- ------ --------------------------------------------------
       355          7 4680   alter system kill session '355,7' immediate;


SYS@test01p> select sql_id,sql_text from V$OPEN_CURSOR where sid=355 and  sql_text like 'table%\_17fd2%' escape '\';
SQL_ID        SQL_TEXT
------------- ------------------------------------------------------------
0dzargq9a6gg3 table_4_9_17fd2_0_0_0

SYS@test01p> select sys.dbms_sqltune_util0.sqltext_to_sqlid('table_4_9_17fd2_0_0_0'||chr(0)) c20 from dual;
C20
--------------------
0dzargq9a6gg3

--很容易猜到這個與lob欄位有關。

2.查詢sql_id=0dzargq9a6gg3:
SYS@test01p> select * from v$sql where sql_id='0dzargq9a6gg3';
no rows selected

SELECT DECODE (kglhdadr,
               kglhdpar, '父遊標控制程式碼地址',
               '子游標控制程式碼地址')
          text,
       kglhdadr,
       kglhdpar,
       substr(kglnaobj,1,20),
       kglobhd0,
       kglobhd6,
       kglobhs0,kglobhs6,kglobt16,
       kglobhs0+kglobhs6+kglobt16,
       kglobhs0+kglobhs1+kglobhs2+kglobhs3+kglobhs4+kglobhs5+kglobhs6+kglobt16 N20
  FROM x$kglob
WHERE kglobt03 = '&1';

TEXT           KGLHDADR         KGLHDPAR         SUBSTR(KGLNAOBJ,1,20)  KGLOBHD0         KGLOBHD6           KGLOBHS0   KGLOBHS6   KGLOBT16 KGLOBHS0+KGLOBHS6+KGLOBT16        N20
-------------- ---------------- ---------------- ---------------------- ---------------- ---------------- ---------- ---------- ---------- -------------------------- ----------
子游標控制程式碼地址 000007FF2668F1C8 000007FF57A166F0 table_4_9_17fd2_0_0_   000007FF2668F110 000007FF2BE09F08       4032       4032       3102                      11166      11166
父遊標控制程式碼地址 000007FF57A166F0 000007FF57A166F0 table_4_9_17fd2_0_0_   000007FF57A16638 00                     4072          0          0                       4072       4072

--不過這種情況查詢查詢x$kglob還是能查詢到的。

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/267265/viewspace-1760052/,如需轉載,請註明出處,否則將追究法律責任。

相關文章