共计 6756 个字符,预计需要花费 17 分钟才能阅读完成。
这篇文章主要为大家展示了“SQL Monitor Report 怎么用”,内容简而易懂,条理清晰,希望能够帮助大家解决疑惑,下面让丸趣 TV 小编带领大家一起研究并学习一下“SQL Monitor Report 怎么用”这篇文章吧。
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
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
在调用函数时加上参数,比如:base_path
= http://ipaddr/sqlmon
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.1Text 文本格式
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
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.2HTML 格式
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.3Active 格式
如不能联网,需要下载相应的 flash 组件、脚本,详细见 SQL Monitor report 获取方法
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 =
http://ipaddr/sqlmon ) AS report
FROM dual;
spool off
2)active 类型报告展示
可以通过启动 http 服务,将文件放置在发布目录下,通过 http://ipaddr/sqlmon/report_sql_monitor_active.html 形式查看(需下载相应的脚本和组件)
或者拿到 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
以上是“SQL Monitor Report 怎么用”这篇文章的所有内容,感谢各位的阅读!相信大家都有了一定的了解,希望分享的内容对大家有所帮助,如果还想学习更多知识,欢迎关注丸趣 TV 行业资讯频道!