sql_monitor实时监控

1 检查数据库是否启用了监控功能

1)检查参数:CONTROL_MANAGEMENT_PACK_ACCES

SQL> show parameter CONTROL_MANAGEMENT_PACK_ACCESS;

NAME                                 TYPE        VALUE

------------------------------------ ----------- ------------------------------

control_management_pack_access       string      DIAGNOSTIC+TUNING

备注:参数值为“DIAGNOSTIC+TUNING”表示SQL 监控启用

2)检查参数:statistic

SQL> show parameter statistic

NAME                                 TYPE        VALUE

------------------------------------ ----------- ------------------------------

optimizer_use_pending_statistics     boolean     FALSE

statistics_level                     string      TYPICAL

timed_os_statistics                  integer     0

timed_statistics                     boolean     TRUE

备注:实时 SQL 监控需要 statistics_level 初始化参数设置为 TYPICAL 或 ALL

2 模拟一个大查询

表gl_je_lines中有120620495条数据,本地查询时间为12.31min

SQL> select count(1) from gl_je_lines gjh;

120620495

3 生成sql_monitor报告

注:主要由SQL的SQL_ID,就可以生成sql_monitor报表

1)获取SQL的SQL_ID

select sm.status,

       sm.username,

       sm.module,

       sm.program,

       (select fcp.user_concurrent_program_name

        from fnd_concurrent_programs_vl fcp

       where fcp.concurrent_program_name  =  sm.module) 请求名称,

       sm.physical_read_bytes / 1024 / 1024 read_io_mb,

       sm.io_interconnect_bytes / 1024 / 1024 read_io_inter_mb,

       sm.*,

       sm.sid,

       sm.client_identifier,

       sm.sql_id,

       sm.sql_text

  from v$sql_monitor sm

 where 1 = 1

   and sm.username = 'APPS'

 --  and sm.module = 'PL/SQL Developer'

 --  and sm.program = 'plsqldev.exe'

 order by sm.physical_read_bytes desc;

得到SQL_ID:5rw111jmvv6xk

2)生成报告(模式:TEXT、HTML、XML、ACTIVE)

A 文本格式报告

select dbms_sqltune.report_sql_monitor(sql_id => '&sqlid', type => 'TEXT') as report

  from dual;

注:输入前面查到的SQL_ID值,得到如下sql_monitor监控报告:

 

B HTML格式

select dbms_sqltune.report_sql_monitor(sql_id       => '&sqlid',

                                       report_level => 'ALL',

                                       type         => 'HTML') comm

  from dual;

注:输入前面查到的SQL_ID值,得到如下sql_monitor监控报告:

 

原文地址:https://www.cnblogs.com/hand-lzs/p/9221204.html