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

lfree發表於2015-08-03

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

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

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

--今天自己google,想想看看還有那種情況會出現呢?如果1條語句執行錯誤,會記錄sql_id,當時查詢v$sql檢視應該也不能找到。
--自己直接那生產系統看看:

1.建立測試環境:
--看看生產系統的情況:
SYS@xxxxxx:1521/dbcn> @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

SELECT COUNT (*), sql_id
    FROM V$ACTIVE_SESSION_HISTORY
   WHERE event = 'SQL*Net break/reset to client'
GROUP BY sql_id having count(*)>=9
ORDER BY 1 DESC;

  COUNT(*) SQL_ID
---------- -------------
       369 cm0qrtprj32qv
         9 c21vhszr9gbdq

SYSTEM@xxxxxx:1521/dbcn> @dpc cm0qrtprj32qv ''
PLAN_TABLE_OUTPUT
-----------------------------------------------------------
SQL_ID: cm0qrtprj32qv cannot be found
--無法發現sql語句。

SYS@192.168.99.106:1521/dbcn> select * from v$sql where sql_id='cm0qrtprj32qv';
no rows selected

--查詢x$kglob檢視:
$ cat shp4.sql
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';


SYS@192.168.99.106:1521/dbcn> @sharepool/shp4 cm0qrtprj32qv
old  14:  WHERE kglobt03 = '&1'
new  14:  WHERE kglobt03 = 'cm0qrtprj32qv'

TEXT           KGLHDADR         KGLHDPAR         SUBSTR(KGLNAOBJ,1,20)                    KGLOBHD0         KGLOBHD6           KGLOBHS0   KGLOBHS6   KGLOBT16 KGLOBHS0+KGLOBHS6+KGLOBT16        N20
-------------- ---------------- ---------------- ---------------------------------------- ---------------- ---------------- ---------- ---------- ---------- -------------------------- ----------
子游標控制程式碼地址 000000130BCC8228 0000001309E41A28 SELECT PBD_FHGT,PBD_                     00               00                        0          0       4091                       4091       4091
子游標控制程式碼地址 000000130570E978 0000001309E41A28 SELECT PBD_FHGT,PBD_                     00               00                        0          0       4091                       4091       4091
父遊標控制程式碼地址 0000001309E41A28 0000001309E41A28 SELECT PBD_FHGT,PBD_                     0000001307FF9158 00                     4976          0          0                       4976       4976

--
SYS@192.168.99.106:1521/dbcn> SELECT distinct kglnaobj c100 from x$kglob where  kglobt03 = 'cm0qrtprj32qv';
C100
----------------------------------------------------------------------------------------------------
SELECT PBD_FHGT,PBD_FWGT,PBD_FITL,PBD_FUNL,PBD_FCHR,PBD_FPTC,PBD_FFCE,PBH_FHGT,PBH_FWGT,PBH_FITL,PBH
_FUNL,PBH_FCHR,PBH_FPTC,PBH_FFCE,PBL_FHGT,PBL_FWGT,PBL_FITL,PBL_FUNL,PBL_FCHR,PBL_FPTC,PBL_FFCE,PBT_
CMNT  FROM SYSTEM.PBCATTBL   WHERE PBT_OWNR = :"SYS_B_0" AND PBT_TNAM = :"SYS_B_1"

--這個是pb的程式,而這個表再我們的系統不存在。
SYS@192.168.99.106:1521/dbcn> @desc SYSTEM.PBCATTBL
ERROR:
ORA-04043: object SYSTEM.PBCATTBL does not exist

--導致每次程式訪問是報錯。

select trunc(sample_time,'hh24'),sql_id,count(*) from V$ACTIVE_SESSION_HISTORY where sql_id='cm0qrtprj32qv' and sample_time>=trunc(sysdate)+8/24
group by trunc(sample_time,'hh24'),sql_id
order by trunc(sample_time,'hh24') desc ,sql_id;

TRUNC(SAMPLE_TIME,' SQL_ID          COUNT(*)
------------------- ------------- ----------
2015-08-03 10:00:00 cm0qrtprj32qv         28
2015-08-03 09:00:00 cm0qrtprj32qv         94
2015-08-03 08:00:00 cm0qrtprj32qv         60

--當前我執行的時間是10:23,看看9-10點,這個錯誤就浪費了94秒時間。可以發現執行實在太頻繁。


--接著看看另外1條語句:

SYS@xxxxxx:1521/dbcn> SELECT distinct kglnaobj c100 from x$kglob where  kglobt03 = 'c21vhszr9gbdq';
C100
----------------------------------------------------------------------------------------------------
Select csz2 From gy_xtcs where xtxh =:"SYS_B_0" And csmc =:"SYS_B_1"

SYS@xxxxxx:1521/dbcn> @desc portal_his.GY_XTCS
Name   Null?    Type
------ -------- ----------------------------
CSMC   NOT NULL VARCHAR2(40)
CSZ             VARCHAR2(200)
MRZ             VARCHAR2(100)
BZ              VARCHAR2(80)

--根本沒有xtxh欄位。
--真不知道這種大量無法執行的命令對效能能產生多大的影響。不過都可以通過x$kglob查詢到。

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

相關文章