Real-Time SQL Monitoring using DBMS_SQLTUNE
Real-Time SQL Monitoring reports are available from three locations:
- Enterprise Manager - Click the "Performance" tab, then the "SQL Monitoring" link at the bottom-right of the page to display the "Monitored SQL Executions" screen. Click the
SQL_ID
of interest to display the SQL monitoring report. - SQL Developer - Available from the "Tools > Monitor SQL" menu.
- DBMS_SQLTUNE package.
In this article I will demonstrate the use of the DBMS_SQLTUNE
package to display SQL monitoring reports without using Enterprise Manager or SQL Developer. This article has been updated to include additional functionality
introduced in Oracle 11g Release 2.
- Introduction
- MONITOR Hint
- REPORT_SQL_MONITOR
- REPORT_SQL_MONITOR_LIST
- REPORT_SQL_DETAIL
- Active HTML Reports Offline
- Views
Related articles.
- Explain Plan Usage
- DBMS_XPLAN : Display Oracle Execution Plans
- SQL trace, 10046, trcsess and tkprof in Oracle
Introduction
Oracle 11g automatically monitors SQL statements if they are run in parallel, or consume 5 or more seconds of CPU or I/O in a single execution. This allows resource intensive SQL to be monitored as it is executing, as well as giving
access to detailed information about queries once they are complete.
SQL monitoring requires the STATISTICS_LEVEL
parameter to be set to 'TYPICAL' or 'ALL', and the CONTROL_MANAGEMENT_PACK_ACCESS
parameter set to 'DIAGNOSTIC+TUNING'.
SQL> CONN / AS SYSDBA
Connected.
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>
MONITOR Hint
The MONITOR
hint switches on SQL monitoring for statements that would not otherwise initiate it.
SELECT /*+ MONITOR */ d.dname, WM_CONCAT(e.ename) AS employees
FROM emp e
JOIN dept d ON e.deptno = d.deptno
GROUP BY d.dname
ORDER BY d.dname;
REPORT_SQL_MONITOR
The REPORT_SQL_MONITOR
function is used to return a SQL monitoring report for a specific SQL statement. The SQL statement can be identified using a variety of parameters, but it will typically be identified using the SQL_ID
parameter.
The function can accept many optional parameters, shown here, but most of the time you will probably
only use the following.
SQL_ID
- TheSQL_ID
of the query of interest. When NULL (the default) the last monitored statement is targeted.SQL_EXEC_ID
- When theSQL_ID
is specified, theSQL_EXEC_ID
indicates the individual execution of interest. When NULL (the default) the most recent execution of the statement targeted by theSQL_ID
is
assumed.REPORT_LEVEL
- The amount of information displayed in the report. The basic allowed values are 'NONE', 'BASIC', 'TYPICAL' or 'ALL', but the information displayed can be modified further by adding (+) or subtracting (-) named report sections
(eg. 'BASIC +PLAN +BINDS' or 'ALL -PLAN'). This is similar to the way DBMS_XPLAN output can be tailored in the later releases. I almost always use 'ALL'.TYPE
- The format used to display the report ('TEXT', 'HTML', 'XML' or 'ACTIVE'). The 'ACTIVE' setting is new to Oracle 11g Release 2 and displays the output using HTML and Flash, similar to the way it is shown in Enterprise Manager.SESSION_ID
- Targets a subset of queries based on the specified SID. UseSYS_CONTEXT('USERENV','SID')
for the current session.
The report accesses several dynamic performance views, so you will most likely access it from a privileged user, or a user granted the SELECT_CATALOG_ROLE
role.
To see it in action, first we make sure we have a monitored statement to work with.
CONN scott/tiger SELECT /*+ MONITOR */ d.dname, WM_CONCAT(e.ename) AS employees
FROM emp e
JOIN dept d ON e.deptno = d.deptno
GROUP BY d.dname
ORDER BY d.dname;
Monitored statements can be identified using the V$SQL_MONITOR
view. This view was present in Oracle 11g Release 1, but has additional columns in Oracle 11g Release 2, making it much more useful. It contains an entry for
each execution monitored, so it can contain multiple entries for individual SQL statements.
CONN / AS SYSDBA -- 11gR1
SELECT sql_id, status
FROM v$sql_monitor; SQL_ID STATUS
------------- -------------------
526mvccm5nfy4 DONE (ALL ROWS) SQL> -- 11gR2
SET LINESIZE 200
COLUMN sql_text FORMAT A80 SELECT sql_id, status, sql_text
FROM v$sql_monitor
WHERE username = 'SCOTT'; SQL_ID STATUS SQL_TEXT
------------- ------------------- --------------------------------------------------------------------------------
526mvccm5nfy4 DONE (ALL ROWS) SELECT /*+ MONITOR */ d.dname, WM_CONCAT(e.ename) AS employees
FROM emp e
JOIN dept d ON e.deptno = d.deptno
GROUP BY d.dname
ORDER BY d.dname SQL>
Once the SQL_ID
is identified, we can generate a report using the REPORT_SQL_MONITOR
function.
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 /host/report_sql_monitor.htm
SELECT DBMS_SQLTUNE.report_sql_monitor(
sql_id => '526mvccm5nfy4',
type => 'HTML',
report_level => 'ALL') AS report
FROM dual;
SPOOL OFF
Examples of the output for each available TYPE
are displayed below.
- TEXT
- HTML
- XML
- ACTIVE - Active HTML available in 11gR2 requires a download of Javascript libraries and a Flash movie from an Oracle website, so
must be used on a PC connected to the internet, unless you download the relevant libraries and use theBASE_PATH
parameter in the function call to identify their location.
REPORT_SQL_MONITOR_LIST
The REPORT_SQL_MONITOR_LIST
function was added in Oracle 11g Release 2 to generate a summary screen, similar to that on the "Monitored SQL Executions" page of Enterprise Manager. There are a number of parameters to filer
the content of the report (shown here), but most of the time you will probably only use the TYPE
and REPORT_LEVEL
parameters,
similar to those in the REPORT_SQL_MONITOR
function. The query below shows how the function can be used.
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 /host/report_sql_monitor_list.htm
SELECT DBMS_SQLTUNE.report_sql_monitor_list(
type => 'HTML',
report_level => 'ALL') AS report
FROM dual;
SPOOL OFF
Examples of the output for each available TYPE
are displayed below.
- TEXT
- HTML
- XML
- ACTIVE - Active HTML is not currently supported, but the parameter list, specifically the
BASE_PATH
, suggest it will be supported in future.
REPORT_SQL_DETAIL
Although not documented as part of Real-Time SQL Monitoring, the REPORT_SQL_DETAIL
function added in Oracle 11g Release 2 returns a report containing SQL monitoring information. Once again, it has several parameters (shown
here), but you will probably only use a subset of them to target specific SQL statements, as shown below.
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 /host/report_sql_detail.htm
SELECT DBMS_SQLTUNE.report_sql_detail(
sql_id => '526mvccm5nfy4',
type => 'ACTIVE',
report_level => 'ALL') AS report
FROM dual;
SPOOL OFF
Examples of the output for each available TYPE
are displayed below.
Active HTML Reports Offline
As mentioned previously, by default Active HTML available in 11gR2 require a download of Javascript libraries and a Flash movie from an Oracle website, so must be used on a PC connected to the internet. An alternative to this is to
download the relevant files to a HTTP server on your network (or local machine) and use the BASE_PATH
parameter to reference those files rather than the Oracle website.
To show this I will create a new directory under a HTTP server on my network and download the relevant files to it.
mkdir -p /var/www/html/sqlmon
cd /var/www/html/sqlmon
wget --mirror --no-host-directories --cut-dirs=1 http://download.oracle.com/otn_software/emviewers/scripts/flashver.js
wget --mirror --no-host-directories --cut-dirs=1 http://download.oracle.com/otn_software/emviewers/scripts/loadswf.js
wget --mirror --no-host-directories --cut-dirs=1 http://download.oracle.com/otn_software/emviewers/scripts/document.js
wget --mirror --no-host-directories --cut-dirs=1 http://download.oracle.com/otn_software/emviewers/sqlmonitor/11/sqlmonitor.swf
When calling functions in the DBMS_SQLTUNE
package, I use the BASE_PATH
parameter with the value of "http://192.168.0.4/sqlmon" so the active report will use the local copies of the files, rather than accessing
them from the internet.
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 /host/report_sql_monitor.htm
SELECT DBMS_SQLTUNE.report_sql_monitor(
sql_id => '526mvccm5nfy4',
type => 'ACTIVE',
report_level => 'ALL',
base_path => 'http://192.168.0.4/sqlmon') AS report
FROM dual;
SPOOL OFF
Views
The SQL monitoring functionality accesses a number of existing views, but two new dynamic performance views have been added specifically as part of it.
For more information see:
Real-Time SQL Monitoring using DBMS_SQLTUNE的更多相关文章
- Real-Time SQL Monitoring
Real-Time SQL Monitoring可以在sql运行的时候监控其性能. 缺省情况下,单个sql执行花费的CPU或I/O时间超过5秒或sql并行执行的时候,Real-Time SQL Mon ...
- Oracle 11g Articles
发现一个比较有意思的网站,http://www.oracle-base.com/articles/11g/articles-11g.php Oracle 11g Articles Oracle Dat ...
- sql monitor生成不了报告& FFS hint不生效两个问题思考
事情的发生就是这么偶然,一步步的深入才能汲取到更深入的知识~~ -------------------START------------------------------------------- ...
- 11g SQL Monitor
1,首先确认两个参数的值 SQL> show parameter statistics_level NAME TYPE VALUE ------- ...
- 【转载】sql monitor
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/27067062/viewspace-2129635/ SQL Monitor Report 1. SQL Monit ...
- Oracle 11g实时SQL监控 v$sql_monitor
Oracle 11g实时SQL监控: 前面提到,在Oracle Database 11g中,v$session视图增加了一些新的字段,这其中包括SQL_EXEC_START和SQL_EXEC_ID, ...
- 10046 trace and sql
1. SQLT 下载 从metalink上下载SQLT工具,参考文档 (以下大部分(SQL可以在sqlt\utl 目录下找到)) 1.1 SQLT 安装 SQLT安装在自己的schema SQLT ...
- Oracle SQL调优系列之SQL Monitor Report
@ 目录 1.SQL Monitor简介 2.捕捉sql的前提 3.SQL Monitor 参数设置 4.SQL Monitor Report 4.1.SQL_ID获取 4.2.Text文本格式 4. ...
- SQL Tuning 基础概述08 - SQL Tuning Advisor
SQL调优顾问 SQL Tuning Advisor的使用案例: 1.构建测试表T 2.定义调整任务 3.修改调整任务参数 4.执行调整任务 5.监控调整任务 6.查看调整任务建议 7.删除调整任务 ...
随机推荐
- 基于指定文本的百度地图poi城市检索的使用(思路最重要)
(转载请注明出处哦)具体的百度地图权限和apikey配置以及基础地图的配置不叙述,百度地图定位可以看这个链接的http://blog.csdn.net/heweigzf/article/details ...
- 【FTP】使用org.apache.commons.net.ftp.FTPClient 实现FTP的上传下载
在此之前,在项目中加上FTP的架包 第一步:配置FTP服务器的相关配置 FtpConfig.java 实体类(配置类) package com.sxd.ftp; public class FtpCo ...
- Eureka的自我保护机制
最近项目在Kubernetes上使用Eureka遇到一些问题,在网站上找到一篇针对Eureka自我保护机制原理的文章,觉得不错,总结如下: Eureka的自我保护特性主要用于减少在网络分区或者不稳定状 ...
- [转] SQL SERVER拼接字符串(字符串中有变量)
本文转自:http://blog.csdn.net/sikaiyuan2008/article/details/7848926 SQL SERVER拼接字符串(字符串中有变量)对我来说是一个难点,总是 ...
- [转]ssis cannot retrieve the column code page info from the ole db provider
本文转自:http://social.msdn.microsoft.com/Forums/sqlserver/en-US/dc1a61f2-1ab8-4ed3-b85c-db6481800b50/er ...
- 〔原创〕Ubuntu Linux Server 9.04 安装全程图解
关于Ubuntu Linux Server 9.04 版本的安装使用.先声明几点: 1. 整个安装过程,都是全英文的,而且,是文本模式,不像Desktop版本,有Livecd的图形化模式.2. 刚开始 ...
- linux grep的选项
grep -i 关闭大写和小写敏感性 grep -v 打印全部不包括. . 的行(屏蔽某些条目) grep -l 打印包括模式的文件名称 grep ...
- 十招让Ubuntu 16.04用起来更得心应手
Ubuntu 16.04是一种长期支持版本(LTS),是Canonical承诺发布五年的更新版.也就是说,你可以让这个版本在电脑上运行五年!这样一来,一开始就设置好显得特别重要.你应该确保你的软件是最 ...
- 在 TDA 工具里看到 Java Thread State 的第一反应是
转载:http://itindex.net/detail/43158-tda-%E5%B7%A5%E5%85%B7-java 使用 TDA 工具,看到大量 Java Thread State 的第 ...
- Win7如何关闭操作中心的图标
运行gpedit.msc,打开组策略编辑器 双击"删除操作中心图标",将其启用即可(重启可见)