SQL 多个查询的监控报告

SQL Monitor report for multiple queries

我需要为一组查询按顺序生成 report_sql_monitor 并假脱机到文件中。 所以我有以下内容:

  1. 查询所在的文件(例如test.sql)
  2. 假脱机文件(例如 output.txt)

Test.sql / Below is the corrected version:

   set pagesize 1000
   set echo off
   set feedback on
   set timing on
   set autotrace on stat
   define file=./output.txt
   define file
   col prev_sql_id new_value SQLID --get the SQL_ID of previous query to put it further into report_sql_monitor
   select /*+ Monitor */ name, last_name from family --first query 
   /
   select prev_id from v$session where sid = sys_context('USERENV','SID') --get SQL_ID
    /
    spool &file
    select dbms_sqltune.report_sql_monitor(
    sql_id => '&SQLID',
    type = > 'TEXT',
    report_level => 'ALL') as report from dual --Report was generated
    /
    spool off --close spooling 
    --the second query
    select /*+ Monitor */ salary,month from salary
    /
    select prev_sql_id from v$session where sid =sys_context('USERENV','SID') --get SQL_ID
    /
    spool &file append
    select dbms_sqltune.report_sql_monitor(
    sql_id => '&SQLID',
    type = > 'TEXT',
    report_level => 'ALL') as report from dual -- REPORT IS NOT GENERATED
    /
    spool off

The problem is that the above test.sql generates report_sql_monitor report only for the first query with 'statistics'. The resulting file (output.txt) is expected to have the following:

  1. SQL 监控报告 test.sql 中的每个查询 - 未完成
  2. 在SQL监控报告之后应该有标准的查询统计数据 - IS DONE:

统计

xx recursive call

xx db block gets

xx consistent gets

xx physical reads

and so forth

来自manual

SQL monitoring is automatically started when a SQL statement runs parallel or when it has consumed at least 5 seconds of CPU or I/O time.

添加MONITOR提示强制监控语句:

select /*+ monitor */ salary,month from salary
/

监控数据也可能由于以下原因而丢失,尽管我怀疑它们是否适用于此处:

  1. 数据老化,通常在几十分钟内。
  2. 阻止监视大的、奇怪的语句的错误。
  3. 控制监视行为的隐藏参数。