实时SQL监控功能(Real-Time SQL Monitoring)是Oracle11g推出的功能,通过这个功能可以实时地监视执行中的SQL性能。
要想使用实时SQL监控功能(Real-Time SQL Monitoring),必须满足以下几个条件
・EE版本,购买了Diagnostics and Tuning Pack License
・STATISTICS_LEVEL参数设为TYPICAL or ALL
・CONTROL_MANAGEMENT_PACK_ACCESS 参数设为 'DIAGNOSTIC+TUNING'
・并行执行的SQL文
・消耗的CPU时间或I/O时间超过5秒的串行执行的SQL文
・指定/*+ MONITOR*/ Hint的SQL
(也通过/*+ NO_MONITOR */ Hint,来使某些SQL为监视对象外)
REPORT_SQL_MONITOR :实时SQL监控报告
REPORT_SQL_MONITOR_LIST :(11.2以后)用于显示概要信息,同V$SQL_MONITOR的内容。
参考:
Database PL/SQL Packages and Types Reference
>140 DBMS_SQLTUNE
>>Real-time SQL Monitoring Subprograms
可以通过直接查询相关动态视图进行实时SQL监控。
V$SQL_MONITOR :实时SQL监控全体概要信息
V$SQL_PLAN_MONITOR :SQL的执行计划信息
Database Reference
>V$SQL_MONITOR
>V$SQL_PLAN_MONITOR
可以通过EM or EM Cloud Control来进行实时SQL监控。
我们可以通过以下方法查看实时SQL监控功能(Real-Time SQL Monitoring)的参数,来进一步了解实时SQL监控功能。
(11.2.0.4版本)
SQL> select a.ksppinm "Parameter",
a.KSPPDESC "Description",b.ksppstvl "Value"
from x$ksppi a, x$ksppcv b
where a.indx = b.indx and a.ksppinm like '%_sqlmon%'; 2 3 4
Parameter Description Value
------------------------ ----------------------------------------------------------------------------- -----
_sqlmon_threshold CPU/IO time threshold before a statement is monitored. 0 is disabled 5
_sqlmon_max_plan Maximum number of plans entry that can be monitored. Defaults to 20 per CPU 40
_sqlmon_max_planlines Number of plan lines beyond which a plan cannot be monitored 300
_sqlmon_recycle_time Minimum time (in s) to wait before a plan entry can be recycled 60
_sqlmon_binds_xml_format format of column binds_xml in [G]V$SQL_MONITOR default
(12.1.0.2版本)
SQL> select a.ksppinm "Parameter",
a.KSPPDESC "Description",b.ksppstvl "Value"
from x$ksppi a, x$ksppcv b
where a.indx = b.indx and a.ksppinm like '%_sqlmon%'; 2 3 4
Parameter Description Value
------------------------------ -------------------------------------------------------------------------------- ----------------------------------------
_sqlmon_threshold CPU/IO time threshold before a statement is monitored. 0 is disabled 5
_sqlmon_max_plan Maximum number of plans entry that can be monitored. Defaults to 20 per CPU 40
_sqlmon_max_planlines Number of plan lines beyond which a plan cannot be monitored 300
_sqlmon_recycle_time Minimum time (in s) to wait before a plan entry can be recycled 5 ★
_sqlmon_binds_xml_format format of column binds_xml in [G]V$SQL_MONITOR default
通过上面的输出,我么可以看到:
_sqlmon_threshold:串行执行的SQL文的监视阈值是5秒CPU/IO时间
_sqlmon_max_plan :V$SQL_MONITOR 中可以保存的执行计划个数( CPU_COUNT*20)
_sqlmon_max_planlines:可监视的最大执行计划行数(300行),当SQL的执行计划行数大于300行时,不会被监视。
_sqlmon_recycle_time:监视对象结束后可以在V$SQL_MONITOR中保存的时间.
11g时为60秒;12c以后为5秒
_sqlmon_binds_xml_format:视图V$SQL_MONITOR 的 binds_xml列的默认格式。
11gR1: 推出该功能
11gR2: DBMS_SQLTUNE.REPORT_SQL_MONITOR程序包增加了 'ACTIVE' 参数,用于显示HTML 和Flash的输出结果
12c: 监视对象结束后可以在V$SQL_MONITOR中保存的时间(_sqlmon_recycle_time),从60秒变为5秒
版权声明:本文为博主原创文章,转载必须注明出处,本人保留一切相关权力!http://blog.csdn.net/lukeunique
测试例:(11.2.0.4)
1.准备测试表和数据
SQL> conn scott/tiger
Connected.
SQL> drop table teacherwhat1;
Table dropped.
SQL> drop table teacherwhat2;
Table dropped.
SQL> create table teacherwhat1(c1 number, c2 char(100));
Table created.
SQL> create table teacherwhat2(c1 number, c2 char(100));
Table created.
SQL> begin
for i in 1 .. 400 loop
for j in 1 .. 300 loop
insert into teacherwhat1 values(i,'A');
insert into teacherwhat2 values(i,'B');
commit;
end loop;
end loop;
end;
/ 2 3 4 5 6 7 8 9 10
PL/SQL procedure successfully completed.
2.执行SQL文
SQL> select /*+ use_nl(a b) */ count(*)
from teacherwhat1 a, teacherwhat2 b
where a.c1=b.c1;
2 3
COUNT(*)
----------
36000000
3.查看执行SQL文的sql_id
SQL> SELECT sql_id, hash_value, substr(sql_text,1,40) sql_text
FROM v$sql
WHERE sql_text like 'select /*+ use_nl(a b) */ count(*)%';
2 3
SQL_ID HASH_VALUE
------------- ----------
SQL_TEXT
--------------------------------------------------------------------------------
dmtsu5j0r3pfn 1097979348
select /*+ use_nl(a b) */ count(*) from
4.查看实时SQL监控结果
4.1 方法1:通过DBMS_SQLTUNE.report_sql_monitor包来显示查看实时SQL监控结果。
4.1.1 HTML形式的输出结果
SQL> spool sql_monitor.html
SQL> SET LONG 1000000
SQL> SELECT DBMS_SQLTUNE.report_sql_monitor(sql_id =>'dmtsu5j0r3pfn',type=> 'HTML') AS report FROM dual;
REPORT
--------------------------------------------------------------------------------
SQL Monitor Report