使用SQL_TEACE的跟蹤檔案分析執行計劃
1、全域性模式的SQL_TRACE:這種跟蹤需要在引數檔案設定SQL_TRACE引數;
sql_trace=true
2、會話模式的SQL_TRACE:這隻能個跟蹤DBA角色使用者開啟的會話;
開啟與關閉跟蹤:
Alter session set sql_trace=true;
Alter session set sql_trace=false;
3、針對某個使用者模式的SQL_TRACE:這個透過呼叫包dbms_system. SET_SQL_TRACE_IN_SESSION
來跟中,需要設定包的相關引數,就可以針對某個使用者開啟的會話進行收集會話詳細的操作過程。
啟用與關閉:
exec dbms_system.SET_SQL_TRACE_IN_SESSION(26,35,true);
exec dbms_system.SET_SQL_TRACE_IN_SESSION(26,35,false);
PROCEDURE SET_SQL_TRACE_IN_SESSION
Argument Name Type In/Out Default?
------------------------------ ----------------------- ------ --------
SID NUMBER IN
SERIAL# NUMBER IN
SQL_TRACE BOOLEAN IN
引數的值可由v$session檢視sid,serial#獲取。以下是測試過程:
----trace跟蹤檔案:
---檢視會話資訊:
sys@PROD>select sid,serial#,username from v$session
2 where username in ('SUXING','SUSU');
SID SERIAL# USERNAME
---------- ---------- ------------------------------
41 829 SUXING
44 417 SUSU
---開啟跟蹤包:
sys@PROD>exec dbms_system.SET_SQL_TRACE_IN_SESSION(44,417,true);
PL/SQL procedure successfully completed.
---使用者會話進行的系列操作:
susu@PROD>insert into sutab values(14,'sskk');
1 row created.
susu@PROD>commit;
Commit complete.
susu@PROD>select * from sutab;
ID NAME
---------- ----
12 susu
13 suxy
14 sskk
---關閉跟蹤包:
sys@PROD>exec dbms_system.SET_SQL_TRACE_IN_SESSION(44,417,false);
PL/SQL procedure successfully completed
---檢視檔案:
[oracle@enmo trace]$ ls -lrt
... ...
-rw-r----- 1 oracle oinstall 85 Dec 6 13:30 PROD_ckpt_4591.trm
-rw-r----- 1 oracle oinstall 1686 Dec 6 13:30 PROD_ckpt_4591.trc
-rw-r----- 1 oracle oinstall 128 Dec 6 16:54 PROD_ora_15427.trm
-rw-r----- 1 oracle oinstall 4050 Dec 6 16:54 PROD_ora_15427.trc
-rw-r----- 1 oracle oinstall 1160 Dec 6 16:54 PROD_mmon_4603.trm
-rw-r----- 1 oracle oinstall 11761 Dec 6 16:54 PROD_mmon_4603.trc
---格式化新生成的trace檔案:
[oracle@enmo trace]$ tkprof PROD_ora_15427.trc susutace.text
TKPROF: Release 11.2.0.4.0 - Development on Tue Dec 6 16:59:12 2016
Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.
[oracle@enmo trace]$ ls susutace.text
susutace.text
[oracle@enmo trace]$
---檢視trace檔案的內容:
[oracle@enmo trace]$ cat susutace.text
TKPROF: Release 11.2.0.4.0 - Development on Tue Dec 6 16:59:12 2016
Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.
Trace file: PROD_ora_15427.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
********************************************************************************
SQL ID: guuy2qrm1mj9n Plan Hash: 0
insert into sutab
values
(14,'sskk')
call count cpu elapsed disk query current rows
------- ------ -------- ---------- ---------- ---------- ---------- ----------
Parse 1 0.00 0.01 0 0 0 0
Execute 1 0.00 0.00 0 1 5 1
Fetch 0 0.00 0.00 0 0 0 0
------- ------ -------- ---------- ---------- ---------- ---------- ----------
total 2 0.00 0.01 0 1 5 1
Misses in library cache during parse: 1
Optimizer mode: ALL_ROWS
Parsing user id: 95
Number of plan statistics captured: 1
Rows (1st) Rows (avg) Rows (max) Row Source Operation
---------- ---------- ---------- ---------------------------------------------------
0 0 0 LOAD TABLE CONVENTIONAL (cr=1 pr=0 pw=0 time=69 us)
********************************************************************************
SQL ID: 23wm3kz7rps5y Plan Hash: 0
commit
call count cpu elapsed disk query current rows
------- ------ -------- ---------- ---------- ---------- ---------- ----------
Parse 1 0.00 0.00 0 0 0 0
Execute 1 0.00 0.00 0 0 1 0
Fetch 0 0.00 0.00 0 0 0 0
------- ------ -------- ---------- ---------- ---------- ---------- ----------
total 2 0.00 0.00 0 0 1 0
Misses in library cache during parse: 0
Parsing user id: 95
********************************************************************************
SQL ID: 96g93hntrzjtr Plan Hash: 2239883476
select /*+ rule */ bucket_cnt, row_cnt, cache_cnt, null_cnt, timestamp#,
sample_size, minimum, maximum, distcnt, lowval, hival, density, col#,
spare1, spare2, avgcln
from
hist_head$ where obj#=:1 and intcol#=:2
call count cpu elapsed disk query current rows
------- ------ -------- ---------- ---------- ---------- ---------- ----------
Parse 1 0.00 0.00 0 0 0 0
Execute 2 0.00 0.00 0 0 0 0
Fetch 2 0.00 0.00 0 6 0 2
------- ------ -------- ---------- ---------- ---------- ---------- ----------
total 5 0.00 0.00 0 6 0 2
Misses in library cache during parse: 1
Misses in library cache during execute: 1
Optimizer mode: RULE
Parsing user id: SYS (recursive depth: 1)
Number of plan statistics captured: 1
Rows (1st) Rows (avg) Rows (max) Row Source Operation
---------- ---------- ---------- ---------------------------------------------------
1 1 1 TABLE ACCESS BY INDEX ROWID HIST_HEAD$ (cr=3 pr=0 pw=0 time=94 us)
1 1 1 INDEX RANGE SCAN I_HH_OBJ#_INTCOL# (cr=2 pr=0 pw=0 time=16 us)(object id 450)
********************************************************************************
SQL ID: 2w7t5suhn4wp1 Plan Hash: 3627255998
select *
from
sutab
call count cpu elapsed disk query current rows
------- ------ -------- ---------- ---------- ---------- ---------- ----------
Parse 1 0.00 0.00 0 0 0 0
Execute 1 0.00 0.00 0 0 0 0
Fetch 2 0.00 0.00 0 7 0 3
------- ------ -------- ---------- ---------- ---------- ---------- ----------
total 4 0.00 0.00 0 7 0 3
Misses in library cache during parse: 1
Optimizer mode: ALL_ROWS
Parsing user id: 95
Number of plan statistics captured: 1
Rows (1st) Rows (avg) Rows (max) Row Source Operation
---------- ---------- ---------- ---------------------------------------------------
3 3 3 TABLE ACCESS FULL SUTAB (cr=7 pr=0 pw=0 time=26 us cost=2 size=17 card=1)
********************************************************************************
OVERALL TOTALS FOR ALL NON-RECURSIVE STATEMENTS
call count cpu elapsed disk query current rows
------- ------ -------- ---------- ---------- ---------- ---------- ----------
Parse 3 0.00 0.01 0 0 0 0
Execute 3 0.00 0.00 0 1 6 1
Fetch 2 0.00 0.00 0 7 0 3
------- ------ -------- ---------- ---------- ---------- ---------- ----------
total 8 0.00 0.01 0 8 6 4
Misses in library cache during parse: 2
OVERALL TOTALS FOR ALL RECURSIVE STATEMENTS
call count cpu elapsed disk query current rows
------- ------ -------- ---------- ---------- ---------- ---------- ----------
Parse 1 0.00 0.00 0 0 0 0
Execute 2 0.00 0.00 0 0 0 0
Fetch 2 0.00 0.00 0 6 0 2
------- ------ -------- ---------- ---------- ---------- ---------- ----------
total 5 0.00 0.00 0 6 0 2
Misses in library cache during parse: 1
Misses in library cache during execute: 1
3 user SQL statements in session.
1 internal SQL statements in session.
4 SQL statements in session.
********************************************************************************
Trace file: PROD_ora_15427.trc
Trace file compatibility: 11.1.0.7
Sort options: default
1 session in tracefile.
3 user SQL statements in trace file.
1 internal SQL statements in trace file.
4 SQL statements in trace file.
4 unique SQL statements in trace file.
66 lines in trace file.
12 elapsed seconds in trace file.
[oracle@enmo trace]$
#以上標顏色底的記錄就是由sql_trace跟蹤所獲得的。來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/31392094/viewspace-2129891/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 轉:使用 Tkprof 分析 ORACLE 跟蹤檔案Oracle
- 跟蹤執行命令T
- 分析執行計劃優化SQLORACLE的執行計劃(轉)優化SQLOracle
- git列出跟蹤的檔案列表Git
- Git跟蹤與提交檔案Git
- .gitignore忽略跟蹤指定檔案Git
- MYSQL sql執行過程的一些跟蹤分析(一)MySql
- explain執行計劃分析AI
- SqlServer的執行計劃如何分析?SQLServer
- MYSQL sql執行過程的一些跟蹤分析(二.mysql優化器追蹤分析)MySql優化
- git刪除未跟蹤檔案Git
- git clean清除未跟蹤檔案Git
- 如何在 Git 中取消檔案的跟蹤Git
- Oracle執行語句跟蹤 使用sql trace實現語句追蹤OracleSQL
- .Oracle固定執行計劃之SQL PROFILE概要檔案OracleSQL
- git列出所有已經跟蹤檔案Git
- DB2執行計劃分析DB2
- 生產環境使用10053分析Oracle的執行計劃Oracle
- 執行計劃-1:獲取執行計劃
- (4) MySQL中EXPLAIN執行計劃分析MySqlAI
- mysql 執行計劃索引分析筆記MySql索引筆記
- MySQL——通過EXPLAIN分析SQL的執行計劃MySqlAI
- 使用OpenCV進行ROS 2的循線跟蹤OpenCVROS
- 【執行計劃】Oracle獲取執行計劃的幾種方法Oracle
- Oracle執行計劃Explain Plan 如何使用OracleAI
- oracle使用outline固定執行計劃事例Oracle
- [20211227]抽取跟蹤檔案中的繫結變數值.txt變數
- 如何制定專案執行計劃的幾種方法
- SQLServer進行SQL跟蹤SQLServer
- MySQL執行計劃MySql
- SYBASE執行計劃
- MySQL 執行計劃MySql
- 妙用 Intellij IDEA 建立臨時檔案,Git 跟蹤不到的那種IntelliJIdeaGit
- 技術管理之路四、任務管理:如何跟蹤執行?
- 使用ErrorStack進行錯誤跟蹤及診斷Error
- Windows下用命令列工具ADRCI跟蹤日誌檔案Windows命令列
- [20191221]12c查詢跟蹤檔案內容.txt
- 【LOG】Oracle資料庫清理日誌、跟蹤檔案利器Oracle資料庫
- DM7使用DMRMAN工具執行加密備份與設定跟蹤日誌加密