【问题标题】:SQL Monitor report for multiple queries多个查询的 SQL 监视器报告
【发布时间】:2015-08-21 16:35:16
【问题描述】:

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

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

Test.sql / 以下是修正后的版本

   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

问题是上面的 test.sql 只为第一个带有“统计”的查询生成 report_sql_monitor 报告。生成的文件 (output.txt) 应具有以下内容:

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

统计

xx recursive call

xx db block gets

xx consistent gets

xx physical reads

and so forth

【问题讨论】:

  • 那么,你的问题是什么?
  • @OldProgrammer report_sql_monitor 不会为第二个查询生成,只为第一个查询生成。但是我需要为 test.sql 中的 每个顺序 查询生成它

标签: sql oracle sqlplus rdbms


【解决方案1】:

来自manual

SQL 监控在 SQL 语句运行时自动启动 并行或当它消耗了至少 5 秒的 CPU 或 I/O 时 时间。

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

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

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

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

【讨论】:

  • 嗨乔恩,很好用。所以我更新了我的脚本,每个人都可以将它用于他们的目标。
猜你喜欢
  • 1970-01-01
  • 2019-01-25
  • 1970-01-01
  • 2022-12-21
  • 1970-01-01
  • 2012-11-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多