[20211221]分析sql語句遇到的問題.txt
[20211221]分析sql語句遇到的問題.txt
--//昨天在跟蹤sql語句時遇到的問題,在測試環境做一個記錄。
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.測試:
SCOTT@book> @ spid
SID SERIAL# PROCESS SERVER SPID PID P_SERIAL# C50
---------- ---------- ------------------------ --------- ------ ------- ---------- --------------------------------------------------
30 4817 38137 DEDICATED 38138 26 182 alter system kill session '30,4817' immediate;
@ 10046on 12
select * from dept where deptno=10;
select * from dept where deptno=10;
select * from dept where deptno=10;
select * from dept where deptno=10;
select * from dept where deptno=10;
select * from dept where deptno=10;
@ 10046off
SCOTT@book> @ti
New tracefile_identifier = /u01/app/oracle/diag/rdbms/book/book/trace/book_ora_38138_0001.trc
@ 10046on 12
select * from dept where deptno=10;
select * from dept where deptno=10;
select * from dept where deptno=10;
select * from dept where deptno=10;
select * from dept where deptno=10;
select * from dept where deptno=10;
@ 10046off
3.問題:
--//開啟跟蹤檔案/u01/app/oracle/diag/rdbms/book/book/trace/book_ora_38138_0001.trc:
$ grep sql_id /u01/app/oracle/diag/rdbms/book/book/trace/book_ora_38138_0001.trc
$ extractsql.sh /u01/app/oracle/diag/rdbms/book/book/trace/book_ora_38138_0001.trc
--//我當時納悶,為什麼跟蹤檔案裡面無法抽取sql語句。檢視第一個跟蹤檔案,馬上發現問題:
$ extractsql.sh /u01/app/oracle/diag/rdbms/book/book/trace/book_ora_38138.trc
select col#, grantee#, privilege#,max(mod(nvl(option$,0),2)) from objauth$ where obj#=:1 and col# is not null group by privilege#, col#, grantee# order by col#, grantee#
select grantee#,privilege#,nvl(col#,0),max(mod(nvl(option$,0),2))from objauth$ where obj#=:1 group by grantee#,privilege#,nvl(col#,0) order by grantee#
select con#,obj#,rcon#,enabled,nvl(defer,0),spare2,spare3 from cdef$ where robj#=:1
select con#,type#,condlength,intcols,robj#,rcon#,match#,refact,nvl(enabled,0),rowid,cols,nvl(defer,0),mtime,nvl(spare1,0),spare2,spare3 from cdef$ where obj#=:1
select intcol#,nvl(pos#,0),col#,nvl(spare1,0) from ccol$ where con#=:1
select * from dept where deptno=10
select * from dept where deptno=10
select * from dept where deptno=10
alter session set events '10046 trace name context off'
--//僅僅看見3次select * from dept where deptno=10,也就是在第3次後該語句是軟軟解析,以後在跟蹤執行計劃不變沒有重分析的情
--//況下,都是軟軟解析,跟蹤檔案就無法看到執行語句了。
--//問題的本質是我在同一個會話裡面跟蹤2次,並且修改跟蹤檔名,我當時就是遇到這樣的情況.
--//如果使用第2個跟蹤檔案執行
$tkprof /u01/app/oracle/diag/rdbms/book/book/trace/book_ora_38138_001.trc
output = aa
TKPROF: Release 11.2.0.4.0 - Development on Wed Dec 22 09:42:26 2021
Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.
$ cat aa.prf
TKPROF: Release 11.2.0.4.0 - Development on Wed Dec 22 09:40:25 2021
Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.
Trace file: /u01/app/oracle/diag/rdbms/book/book/trace/book_ora_38138_0001.trc
Sort options: default
********************************************************************************
count = number of times OCI procedure was executed
cpu = cpu time in seconds executing
elapsed = elapsed time in seconds executing
disk = number of physical reads of buffers from disk
query = number of buffers gotten for consistent read
current = number of buffers gotten in current mode (usually for update)
rows = number of rows processed by the fetch or execute call
********************************************************************************
Trace file: /u01/app/oracle/diag/rdbms/book/book/trace/book_ora_38138_0001.trc
Trace file compatibility: 11.1.0.7
Sort options: default
1 session in tracefile.
0 user SQL statements in trace file.
0 internal SQL statements in trace file.
0 SQL statements in trace file.
0 unique SQL statements in trace file.
96 lines in trace file.
7 elapsed seconds in trace file.
4. 附上extractsql.sh指令碼:
$ cat extractsql.sh
#! /bin/bash
awk '/PARSING IN CURSOR/,/END OF STMT/' $1 | egrep -v '^PARSING|^END OF STMT'
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/267265/viewspace-2848773/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- [20230329]記錄除錯sql語句遇到的問題.txt除錯SQL
- [20201105]再分析sql語句.txtSQL
- [20211229]toad下優化sql語句注意的問題.txt優化SQL
- [20211229]sql語句包含中文儲存clob的編碼問題.txtSQL
- [20181119]sql語句執行緩慢分析.txtSQL
- [20210923]sql語句佔用Sharable Memory分析.txtSQL
- [20211221]記錄使用sqlplus的小問題補充.txtSQL
- [20220117]超長sql語句.txtSQL
- [20201210]sql語句優化.txtSQL優化
- [20200326]dbms_monitor跟蹤與SQL語句分析.txtSQL
- [20240607]PL/SQL中sql語句的註解.txtSQL
- [20210407]分析sql語句的共享記憶體段3.txtSQL記憶體
- [20240320]空格與sqlpus的sql語句.txtSQL
- [20200320]SQL語句優化的困惑.txtSQL優化
- [20241110]使用xto10.sql指令碼遇到的問題.txtSQL指令碼
- [20220331]如何調整sql語句.txtSQL
- [20190321]測試相同語句遇到導致cursor pin S的疑問.txt
- [20181114]一條sql語句的優化.txtSQL優化
- 50個SQL語句(MySQL版) 問題十四MySql
- [20211009]使用bash計算sql語句的sql_id.txtSQL
- [20200324]SQL語句優化的困惑2.txtSQL優化
- [20210112]ashtop查詢特定表的SQL語句.txtSQL
- [20191101]通過zsh計算sql語句的sql_id.txtSQL
- [20191011]通過bash計算sql語句的sql_id.txtSQL
- [20220329]是否開發寫錯sql語句.txtSQL
- [20211210]優化遇到的奇怪問題.txt優化
- [20221125]設定hugepages遇到的問題.txt
- [20201214]查詢隱式轉換的sql語句.txtSQL
- 20201214]查詢隱式轉換的sql語句.txtSQL
- [20220111]該語句的sql_id如何計算的.txtSQL
- [20190221]sql patch 問題.txtSQL
- 多語言遇到的問題
- sql語句執行緩慢分析SQL
- [20211224]vim外掛格式化sql語句.txtSQL
- [20211231]vim自動格式化sql語句.txtSQL
- [20220119]超長sql語句補充3.txtSQL
- [20220329]19c sql語句打補丁.txtSQL
- [20220120]超長sql語句補充4.txtSQL