如何在 Oracle 中顯示 SQL 執行進度以及執行計劃?
問題
你想在 SQL 執行計劃中檢視 Oracle SQL 花費了多長時間。
解決方案
在 Oracle 11g 版本中,可以在 SQL 執行期間檢視 SQL 執行計劃進度。“V$SQL_PLAN_MONITOR”檢視包含 SQL 語句執行計劃中每一步的一行。以下 SQL 將有助於檢視執行計劃以及進度。
“V$SQL_PLAN_MONITOR”為你提供有關使用最多資源的步驟資訊。“V$SQL_PLAN_MONITOR”中的統計資料每秒更新一次。
我們還可以透過使用 DBMS_SQLTUNE 包的 REPORT_SQL_MONITOR 函式,生成查詢在執行計劃中進度的一個即時文字、HTML 甚至 XML 報告。
示例
select a.sid ,a.status ,to_char(a.sql_exec_start,'yymmdd hh24:mi') start_time ,a.plan_line_id ,a.plan_operation ,a.plan_options ,a.output_rows ,a.workarea_mem mem_bytes ,a.workarea_tempseg temp_bytes from v$sql_plan_monitor a ,v$sql_monitor b where a.status NOT LIKE '%DONE%' and a.key = b.key order by a.sid, a.sql_exec_start, a.plan_line_id;
生成一個 HTML 報告。
示例
SET LINES 3000 PAGES 0 LONG 1000000 TRIMSPOOL ON SPOOL report.html select dbms_sqltune.report_sql_monitor(session_id=> 901, event_detail => 'YES' ,report_level => 'ALL' ,type => 'HTML' ) from dual; SPOOL OFF;