SQL Monitor Report 使用詳解
1. SQL Monitor簡介
在Oracle Database 11g中,系統自動監控符合以下條件的SQL,並收集執行時的細節資訊:
1)採用並行方式執行
2)單次執行消耗的CPU或IO超過5秒
3)透過使用/* +MONITOR*/ HINT的語句
系統收集的SQL資訊會儲存在V$SQL_MONITOR、V$SQL_PLAN_MONITOR檢視中
2. SQL Monitor 引數設定
STATISTICS_LEVEL設定為:'TYPICAL'(預設)或者 'ALL'
CONTROL_MANAGEMENT_PACK_ACCESS設定為:'DIAGNOSTIC+TUNING'
3. SQL Monitor report獲取方法
SQL Monitoring可以採用以下3種方式展現:
1)EM:Performance ——>右下角的SQL Monitoring ——>Monitored SQL Executions
2)SQL Developer:Tools ——>Monitor SQL
3)DBMS_SQLTUNE包 ——> DBMS_SQLTUNE.report_sql_monitor
其報告格式有:'TEXT','HTML','XML' ,'ACTIVE',其中'ACTIVE'只在11g R2以後才支援,使用HTML和Flash的方式顯示動態的報告,需要從oracle官網讀取相關聯的Javascript和Flash。
備註:
如果不能連到Internet又想看ACTIVE Report可以下載相關的庫檔案到本地的HTTP伺服器上,然後用BASE_PATH來制定庫檔案的位置。
在本地HTTP伺服器上建立目錄,然後下載下面的檔案:
mkdir -p /var/www/html/sqlmon
cd /var/www/html/sqlmon
wget --mirror --no-host-directories --cut-dirs=1
wget --mirror --no-host-directories --cut-dirs=1
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
在呼叫函式時加上引數,比如:base_path => ''
4. SQL Monitor report生成例項
語法:
DBMS_SQLTUNE.REPORT_SQL_MONITOR()
FUNCTION REPORT_SQL_MONITOR RETURNS CLOB
Argument Name Type In/Out Default?
------------------------------ ----------------------- ------ --------
SQL_ID VARCHAR2 IN DEFAULT
SESSION_ID NUMBER IN DEFAULT
SESSION_SERIAL NUMBER IN DEFAULT
SQL_EXEC_START DATE IN DEFAULT
SQL_EXEC_ID NUMBER IN DEFAULT
INST_ID NUMBER IN DEFAULT
START_TIME_FILTER DATE IN DEFAULT
END_TIME_FILTER DATE IN DEFAULT
INSTANCE_ID_FILTER NUMBER IN DEFAULT
PARALLEL_FILTER VARCHAR2 IN DEFAULT
PLAN_LINE_FILTER NUMBER IN DEFAULT
EVENT_DETAIL VARCHAR2 IN DEFAULT
BUCKET_MAX_COUNT NUMBER IN DEFAULT
BUCKET_INTERVAL NUMBER IN DEFAULT
BASE_PATH VARCHAR2 IN DEFAULT
LAST_REFRESH_TIME DATE IN DEFAULT
REPORT_LEVEL VARCHAR2 IN DEFAULT
TYPE VARCHAR2 IN DEFAULT
SQL_PLAN_HASH_VALUE NUMBER IN DEFAULT
4.1 Text文字格式
1) Sqlplus 引數設定檢視
show
parameter statistics_level;
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
statistics_level string TYPICAL
show
parameter CONTROL_MANAGEMENT_PACK_ACCESS;
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
control_management_pack_access string DIAGNOSTIC+TUNING
2) 執行模擬SQL
[oracle@node4 sqlmonitor]$ sqlplus -S /nolog
conn /as sysdba;
select /* +moniotr*/* from scott.dept where deptno<=30;
DEPTNO DNAME LOC
---------- -------------- -------------
10 ACCOUNTING NEW YORK
20 RESEARCH DALLAS
30 SALES CHICAGO
3) 從v$sql_monitor獲取模擬SQL資訊
col sql_text for a60;
set line 200;
set pagesize 20000;
select sql_id,sql_text from v$sql_monitor where sql_text like '%scott.dept%';
SQL_ID SQL_TEXT
------------- ------------------------------------------------------------
74qqqwntwzxb1 select /*+ Monitor*/ * from scott.dept where deptno=10
4) 生成text型別報告
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 report_sql_monitor_text.txt
SELECT DBMS_SQLTUNE.REPORT_SQL_MONITOR(
SQL_ID => '74qqqwntwzxb1',
TYPE => 'TEXT',
REPORT_LEVEL => 'ALL') AS REPORT
FROM dual;
spool off
5) 展示報告內容
4.2 HTML格式
1)生成HTML型別報告
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 report_sql_monitor_html.html
SELECT DBMS_SQLTUNE.REPORT_SQL_MONITOR(
SQL_ID => '74qqqwntwzxb1',
TYPE => 'HTML',
REPORT_LEVEL => 'ALL') AS REPORT
FROM dual;
spool off
2)html型別報告展示
4.3 Active格式
如不能聯網,需要下載相應的flash元件、指令碼,詳細見
1)active型別報告生成
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 report_sql_monitor_active.html
SELECT DBMS_SQLTUNE.REPORT_SQL_MONITOR(
SQL_ID => '74qqqwntwzxb1',
TYPE => 'ACTIVE',
REPORT_LEVEL => 'ALL',
BASE_PATH => '') AS report
FROM dual;
spool off
2)active型別報告展示
可以透過啟動http服務,將檔案放置在釋出目錄下,透過形式檢視(需下載相應的指令碼和元件)
或者拿到windows本地檢視
5. SQL Monitor report其他方法使用
1)DBMS_SQLTUNE.REPORT_SQL_MONITOR_LIST
FUNCTION REPORT_SQL_MONITOR_LIST RETURNS CLOB
Argument Name Type In/Out Default?
------------------------------ ----------------------- ------ --------
SQL_ID VARCHAR2 IN DEFAULT
SESSION_ID NUMBER IN DEFAULT
SESSION_SERIAL NUMBER IN DEFAULT
INST_ID NUMBER IN DEFAULT
ACTIVE_SINCE_DATE DATE IN DEFAULT
ACTIVE_SINCE_SEC NUMBER IN DEFAULT
LAST_REFRESH_TIME DATE IN DEFAULT
REPORT_LEVEL VARCHAR2 IN DEFAULT
AUTO_REFRESH NUMBER IN DEFAULT
BASE_PATH VARCHAR2 IN DEFAULT
TYPE VARCHAR2 IN DEFAULT
需要Oracle 11g R2以上版本。此函式用於產生一個對監控SQL的彙總頁,類似於EM中的“Monitored SQL Executions”。
常用引數:TYPE和REPORT_LEVEL,用法與REPORT_SQL_MONITOR類似。
例如:
conn /as sysdba;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 REPORT_SQL_MONITOR_LIST.HTML
SELECT dbms_sqltune.report_sql_monitor_list(
type => 'HTML',
report_level => 'ALL') AS report
FROM dual;
SPOOL OFF
2)DBMS_SQLTUNE.REPORT_SQL_DETAIL
FUNCTION REPORT_SQL_DETAIL RETURNS CLOB
Argument Name Type In/Out Default?
------------------------------ ----------------------- ------ --------
SQL_ID VARCHAR2 IN DEFAULT
SQL_PLAN_HASH_VALUE NUMBER IN DEFAULT
START_TIME DATE IN DEFAULT
DURATION NUMBER IN DEFAULT
INST_ID NUMBER IN DEFAULT
DBID NUMBER IN DEFAULT
EVENT_DETAIL VARCHAR2 IN DEFAULT
BUCKET_MAX_COUNT NUMBER IN DEFAULT
BUCKET_INTERVAL NUMBER IN DEFAULT
TOP_N NUMBER IN DEFAULT
REPORT_LEVEL VARCHAR2 IN DEFAULT
TYPE VARCHAR2 IN DEFAULT
DATA_SOURCE VARCHAR2 IN DEFAULT
END_TIME DATE IN DEFAULT
DURATION_STATS NUMBER IN DEFAULT
需要Oracle 11g R2以上版本。此函式用於根據各種條件引數(包括:start_time, end_time, duration, inst_id, dbid, event_detail,
bucket_max_count, bucket_interval, top_n, duration_stats),產生比使用REPORT_SQL_MONITOR更加詳細的SQL報告。
例如:
conn /as sysdba;
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 REPORT_SQL_DETAIL_HTML.HTML
SELECT dbms_sqltune.REPORT_SQL_DETAIL(SQL_ID => '74qqqwntwzxb1',
TYPE => 'active',
report_level => 'ALL') AS report
FROM dual;
SPOOL OFF
ERROR:
ORA-13971: Component "sql_detail" unknown
ORA-06512: at "SYS.DBMS_SYS_ERROR", line 95
ORA-06512: at "SYS.DBMS_REPORT", line 166
ORA-06512: at "SYS.DBMS_REPORT", line 612
ORA-06512: at "SYS.DBMS_REPORT", line 1079
ORA-06512: at "SYS.DBMS_REPORT", line 1135
ORA-06512: at "SYS.DBMS_SQLTUNE", line 20101
ORA-06512: at line 1
(上述錯誤在指定html格式,調整為active格式即可)
可以針對topSQL
conn /as sysdba;
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 REPORT_SQL_DETAIL.HTML
SELECT dbms_sqltune.report_sql_detail(top_n => 5,
TYPE => 'active',
report_level => 'ALL') AS report
FROM dual;
SPOOL OFF
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/25462274/viewspace-2150764/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 使用sql monitor獲取更加詳細的執行計劃 - dbms_sqltune.report_sql_monitorSQL
- plsql developer工具生成sql monitor reportSQLDeveloper
- 生成sql monitor active report指令碼SQL指令碼
- Oracle SQL調優系列之SQL Monitor ReportOracleSQL
- sql monitor的使用(一)SQL
- 【SQL】Oracle SQL monitorSQLOracle
- RMAN的list和report命令詳解
- Oracle11g使用sql_monitor實時監控sqlOracleSQL
- Oracle Real Time SQL MonitorOracleSQL
- EBS SQL --> Form & ReportSQLORM
- Oracle Rman 命令詳解(List report backup configure)Oracle
- 11g新動態效能檢視V$SQL_MONITOR,V$SQL_PLAN_MONITORSQL
- sql server dbcc常用命令使用詳解SQLServer
- Monitor All SQL Queries in MySQL (alias mysql profiler)MySql
- Monitor Current SQL Running(10g)SQL
- Oralce 使用SQL中的exists 和not exists 用法詳解SQL
- Elasticsearch SQL用法詳解ElasticsearchSQL
- pl/sql record 詳解SQL
- SQL*Loader 詳解SQL
- Ice中Monitor的使用
- mysql的三個sql的monitor選項MySql
- SQL Monitor,你值得掌握的一個特性SQL
- Hive sql語法詳解HiveSQL
- SQL解析器詳解SQL
- Mybatis 動態 SQL 詳解MyBatisSQL
- SQL 注入技術詳解SQL
- 詳解 SQL 集合運算SQL
- 轉 ------ sql load 詳解SQL
- 詳解sql*plus spool命令SQL
- MySQL SQL_MODE詳解MySql
- Script to generate AWR report from remote sql clientREMSQLclient
- WEB PL/SQL Report 的開發方法WebSQL
- 【SQL】Oracle 19c SQL隔離詳解(SQL Quarantine)SQLOracle
- 解決 httprunner2 無法使用 extent_report_templateHTTP
- 1.Monitor Current SQL Running(10g)SQL
- Statement Tracer For Oracle 與 SQL Monitor 的比較OracleSQL
- 掌握SQL Monitor這些特性,SQL最佳化將如有神助!SQL
- SQL Server:觸發器詳解SQLServer觸發器