DBMS_SQLTUNE.REPORT_SQL_MONITOR

2020-12-02  本文已影响0人  答春竹
SQL_MONITOR

SQL_MONITOR是一个比较好的查看真正执行计划的方式
可以从以下方式获取

SQL_MONITOR为SQL开启监视的条件:

statistics_level 为'TYPICAL' 或者 'ALL'以及CONTROL_MANAGEMENT_PACK_ACCESS 'DIAGNOSTIC+TUNING'.

SQL> SHOW PARAMETER statistics_level

NAME                     TYPE    VALUE
------------------------------------ ----------- ------------------------------
statistics_level             string  TYPICAL

SQL> SHOW PARAMETER control_management_pack_access

NAME                     TYPE    VALUE
------------------------------------ ----------- ------------------------------
control_management_pack_access       string  DIAGNOSTIC+TUNING

自动监视需要SQL在并行parallel或者执行时间超过5S
可以手动给sql加hint 以达到SQL监视的效果/*+ MONITOR */
如:

SELECT /*+ MONITOR */ * from user_tables;
DBMS_SQLTUNE.REPORT_SQL_MONITOR的参数:
V$SQL_MONITOR

可以通过V$SQL_MONITOR视图查看当前正在监视的所有SQL

使用方式

能提前获取SQL_ID,可从v$sql,v$sql_area,v$sql_monitor查看,直接替换sql_id内容即可

SET LONG 1000000
SET LONGCHUNKSIZE 1000000
SET LINESIZE 1000
SET PAGESIZE 0
SET TRIM ON
SET TRIMSPOOL ON
SET ECHO OFF
SET FEEDBACK OFF

SPOOL /home/oracle/report_sql_monitor1.htm
SELECT DBMS_SQLTUNE.report_sql_monitor(
  sql_id       => '526mvccm5nfy4',
  type         => 'ACTIVE',
  report_level => 'ALL') AS report
FROM dual;
SPOOL OFF

如果可以跑SQL,则跑完sql后直接获取

SET LONG 1000000
SET LONGCHUNKSIZE 1000000
SET LINESIZE 1000
SET PAGESIZE 0
SET TRIM ON
SET TRIMSPOOL ON
SET ECHO OFF
SET FEEDBACK OFF
select /* MONITOR */ * from user_tables;
SPOOL /home/oracle/report_sql_monitor2.htm
select dbms_sqltune.report_sql_monitor(
  type=>'active', 
  session_id=>userenv('sid'),
report_level=>'ALL') AS report 
from dual;
SPOOL OFF

也可以从pl/sql跑出来后直接选择html保存:

select /* MONITOR */ * from user_tables;
select dbms_sqltune.report_sql_monitor(type=>'active', session_id=>userenv('sid'),report_level=>'ALL') monitor_report from dual;

点击... -->HTML-->另存为

上一篇下一篇

猜你喜欢

热点阅读