使用DBMS_TRACE對PL/SQL進行跟蹤
可以使用DBMS_TRACE對PL/SQL進行跟蹤,典型的跟蹤過程如下:
*開始PL/SQL跟蹤(DBMS_TRACE.SET_PLSQL_TRACE)
*執行PL/SQL
*停止PL/SQL跟蹤(DBMS_TRACE.CLEAR_PLSQL_TRACE(trace_level))
1,簡介
1.1可以透過debug方式編譯開啟對特定程式單元的跟蹤,方式如下:
alter session set plsql_debug=true;
create or replace ... /* create the library units - debug information will be generated */
或:
/* recompile specific library unit with debug option */
alter [PROCEDURE | FUNCTION | PACKAGE BODY]
1.2可以透過如下引數限制資料庫儲存最近8192條跟蹤記錄:
SET_PLSQL_TRACE儲存過程TRACE_LEVEL引數中包含TRACE_LIMIT
1.3 建立儲存收集資料的表,以SYS使用者執行
?/rdbms/admin/tracetab.sql
?/rdbms/admin/dbmspbt.sql包含跟蹤型別宣告
1.4 跟蹤級別
跟蹤呼叫級別:
* Level 1: Trace all calls. This corresponds to the constant trace_all_calls.
* Level 2: Trace calls to enabled program units only. This corresponds to the constant trace_enabled_calls.
注:Enabling cannot be detected for remote procedure calls (RPCs); hence, RPCs are only traced with level 1.
無論呼叫程式還是被呼叫程式開啟跟蹤,則滿足開啟跟蹤條件。
跟蹤例外級別:
* Level 1: Trace all exceptions. This corresponds to trace_all_exceptions.
* Level 2: Trace exceptions raised in enabled program units only. This corresponds to trace_enabled_exceptions.
跟蹤SQL級別:
* Level 1: Trace all SQL. This corresponds to the constant trace_all_sql.
* Level 2: Trace SQL in enabled program units only. This corresponds to the constant trace_enabled_sql.
跟蹤行級別:
* Level 1: Trace all lines. This corresponds to the constant trace_all_lines.
* Level 2: Trace lines in enabled program units only. This corresponds to the constant trace_enabled_lines.
2,測試
10g版本需要以SYS使用者執行?/rdbms/admin/tracetab.sql:
SQL> select * from v$version;
BANNER
----------------------------------------------------------------
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Prod
PL/SQL Release 10.2.0.1.0 - Production
CORE 10.2.0.1.0 Production
TNS for Linux: Version 10.2.0.1.0 - Production
NLSRTL Version 10.2.0.1.0 - Production
SQL> show user
USER is "SYS"
SQL> @?/rdbms/admin/tracetab.sql
--建立測試用儲存過程
create or replace procedure prc_test(p_num in number) as
l_dummy number := 0;
begin
for i in 1..p_num loop
select l_dummy + 1 into l_dummy from dual;
end loop;
end;
/
--以不同的跟蹤級別執行三次
BEGIN
DBMS_TRACE.set_plsql_trace (DBMS_TRACE.trace_all_calls);
prc_test(100);
DBMS_TRACE.clear_plsql_trace;
DBMS_TRACE.set_plsql_trace (DBMS_TRACE.trace_all_sql);
prc_test(100);
DBMS_TRACE.clear_plsql_trace;
DBMS_TRACE.set_plsql_trace (DBMS_TRACE.trace_all_lines);
prc_test(100);
DBMS_TRACE.clear_plsql_trace;
END;
/
SQL> select runid,run_owner from sys.plsql_trace_runs;
RUNID RUN_OWNER
---------- -------------------------------
1 MH
2 MH
3 MH
set linesize 120
col runid for 999
col event_seq for 99999
col event_unit for a15
col event_unit_kind for a20
col event_line for 9999
--trace all call
select runid,event_seq,event_unit,event_unit_kind,event_line from sys.plsql_trace_events where runid=1;
RUNID EVENT_SEQ EVENT_UNIT EVENT_UNIT_KIND EVENT_LINE
----- --------- --------------- -------------------- ----------
1 1
1 2
1 3 DBMS_TRACE PACKAGE BODY 21
1 4 DBMS_TRACE PACKAGE BODY 67
1 5 DBMS_TRACE PACKAGE BODY 72
1 6
1 7 PRC_TEST PROCEDURE 7
1 8
1 9 DBMS_TRACE PACKAGE BODY 76
1 10 DBMS_TRACE PACKAGE BODY 63
1 11 DBMS_TRACE PACKAGE BODY 57
1 12 DBMS_TRACE PACKAGE BODY 12
1 13 DBMS_TRACE PACKAGE BODY 58
1 14 DBMS_TRACE PACKAGE BODY 66
1 15
--trace all sql
col event_comment for a30
select runid,event_seq,event_unit,event_unit_kind,event_line,event_comment from sys.plsql_trace_events where runid=2;
RUNID EVENT_SEQ EVENT_UNIT EVENT_UNIT_KIND EVENT_LINE EVENT_COMMENT
----- --------- --------------- -------------------- ---------- -------------------------
2 1 PL/SQL Trace Tool started
2 2 Trace flags changed
2 3 PRC_TEST PROCEDURE 5 SELECT :B1 + 1 FROM DUAL
2 4 PRC_TEST PROCEDURE 5 SELECT :B1 + 1 FROM DUAL
2 5 PRC_TEST PROCEDURE 5 SELECT :B1 + 1 FROM DUAL
2 6 PRC_TEST PROCEDURE 5 SELECT :B1 + 1 FROM DUAL
...
2 98 PRC_TEST PROCEDURE 5 SELECT :B1 + 1 FROM DUAL
2 99 PRC_TEST PROCEDURE 5 SELECT :B1 + 1 FROM DUAL
2 100 PRC_TEST PROCEDURE 5 SELECT :B1 + 1 FROM DUAL
2 101 PRC_TEST PROCEDURE 5 SELECT :B1 + 1 FROM DUAL
2 102 PRC_TEST PROCEDURE 5 SELECT :B1 + 1 FROM DUAL
2 103 PL/SQL trace stopped
103 rows selected.
--trace all line
RUNID EVENT_SEQ EVENT_UNIT EVENT_UNIT_KIND EVENT_LINE EVENT_COMMENT
----- --------- --------------- -------------------- ---------- -------------------------
3 1 PL/SQL Trace Tool started
3 2 Trace flags changed
3 3 DBMS_TRACE PACKAGE BODY 66 New line executed
3 4 DBMS_TRACE PACKAGE BODY 67 New line executed
3 5 DBMS_TRACE PACKAGE BODY 72 New line executed
3 6
3 7 PRC_TEST PROCEDURE 2 New line executed
3 8 PRC_TEST PROCEDURE 4 New line executed
3 9 PRC_TEST PROCEDURE 5 New line executed
3 10 PRC_TEST PROCEDURE 4 New line executed
3 11 PRC_TEST PROCEDURE 5 New line executed
...
3 206 PRC_TEST PROCEDURE 4 New line executed
3 207 PRC_TEST PROCEDURE 5 New line executed
3 208 PRC_TEST PROCEDURE 4 New line executed
3 209 PRC_TEST PROCEDURE 7 New line executed
3 210
3 211 DBMS_TRACE PACKAGE BODY 76 New line executed
3 212 DBMS_TRACE PACKAGE BODY 63 New line executed
3 213 DBMS_TRACE PACKAGE BODY 57 New line executed
3 214 DBMS_TRACE PACKAGE BODY 12 New line executed
3 215 DBMS_TRACE PACKAGE BODY 57 New line executed
3 216 DBMS_TRACE PACKAGE BODY 58 New line executed
3 217 DBMS_TRACE PACKAGE BODY 63 New line executed
3 218 DBMS_TRACE PACKAGE BODY 66 New line executed
3 219 DBMS_TRACE PACKAGE BODY 21 New line executed
3 220 PL/SQL trace stopped
220 rows selected.
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/18922393/viewspace-755353/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- SQLServer進行SQL跟蹤SQLServer
- 如何使用PL/SQL進行分級查詢WPSQL
- Oracle執行語句跟蹤 使用sql trace實現語句追蹤OracleSQL
- 使用ErrorStack進行錯誤跟蹤及診斷Error
- 使用OpenCV進行ROS 2的循線跟蹤OpenCVROS
- Spring Cloud Sleuth 和 Zipkin 進行分散式跟蹤使用指南SpringCloud分散式
- Oracle資料庫跟蹤SQLOracle資料庫SQL
- DM7聯機執行SQL語句進行加密備份與設定跟蹤日誌SQL加密
- 利用errorstack事件進行錯誤跟蹤和診斷Error事件
- 如何在非同步結果返回時進行跟蹤非同步
- MYSQL sql執行過程的一些跟蹤分析(一)MySql
- 跟蹤執行命令T
- Oracle 的PL/SQL語言使用OracleSQL
- PL/SQL 宣告SQL
- Oracle PL/SQLOracleSQL
- 使用profiler測試Oracle PL/SQL效能OracleSQL
- MYSQL sql執行過程的一些跟蹤分析(二.mysql優化器追蹤分析)MySql優化
- pl/sql to_dateSQL
- PL/SQL 運算子SQL
- PL/SQL 條件SQL
- PL/SQL 迴圈SQL
- PL/SQL 遊標SQL
- 使用CmBacktrace進行HardFault_Handler 追蹤
- 使用Amazon Pinpoint對使用者行為追蹤
- 使用 Python 和 Prometheus 跟蹤天氣PythonPrometheus
- 如何使用iPhone限制IP地址跟蹤iPhone
- 使用 Emacs 進行社交併跟蹤你的待辦事項列表Mac
- 如何使用專案問題追蹤軟體跟進管理專案
- [20200326]dbms_monitor跟蹤與SQL語句分析.txtSQL
- 如何收集Oracle程式中的SQL跟蹤資訊KUOracleSQL
- 分散式跟蹤系統——產品對比分散式
- 跟我學SpringCloud | 第十一篇:使用Spring Cloud Sleuth和Zipkin進行分散式鏈路跟蹤SpringGCCloud分散式
- 「Oracle」客戶端 PL/SQL DEVELOPER 安裝使用Oracle客戶端SQLDeveloper
- 用 golang 原生 sql 對 MySQL 進行 curdGolangMySql
- pl/sql中三種遊標迴圈效率對比SQL
- 轉:使用 Tkprof 分析 ORACLE 跟蹤檔案Oracle
- Java呼叫鏈跟蹤關鍵技術(四)SQL監控JavaSQL
- 美國邊境官員測試區塊鏈進行證書跟蹤區塊鏈
- DBMS_TRACE(zt)