How To Get Historical SQL Monitor Report For SQL Statements (Doc ID 2555350.1)
In this Document
| Goal |
| Solution |
| References |
APPLIES TO:
Oracle Database - Enterprise Edition - Version 12.1.0.2 and laterInformation in this document applies to any platform.
GOAL
Goal of this document is to explain how to generate or extract historical SQL monitoring report for SQL statements using command line or EM (Enterprise Manager).
One of the major limitations with SQL Monitoring framework is that the information are quickly aged out of memory and not stored in AWR.
From 12c onwards, there are ways to extract the historical SQL monitor report using APIs like DBMS_PERF or DBMS_AUTO_REPORT and also
from Performance Hub page through Oracle Enterprise Manager though not directly through DBMS_SQL_MONITOR which is only for real-time.
Refer the below document for SQL monitoring:
Document 1380492.1 Monitoring SQL Statements with Real-Time SQL Monitoring
SOLUTION
1. Historical SQL monitoring report can be extracted using Performance hub report either through EM or using command-line. Under "Monitored SQL" section of the historical performance hub report shows the historical SQL monitoring information.
Example: To generate Performance Hub in historical mode through command line.
SQL> spool perfhub_history.html
SQL> select dbms_perf.report_perfhub(is_realtime=>0,type=>'active',selected_start_time=>to_date('10-SEP-18 04:00:00','dd-MON-YY hh24:mi:ss'),selected_end_time=>to_date('10-SEP-18 05:00:00','dd-MON-YY hh24:mi:ss')) from dual;
SQL> spool off
2. Historical SQL monitoring report can be extracted for particular SQL statement using SQL Details report.
Example: To generate SQL details report to get the SQL monitoring information for particular SQL statement in historical mode.
SQL> spool sql_details_history.html
SQL> select dbms_perf.report_sql(sql_id=>'9vkyyg1xj6fgc',is_realtime=>0,type=>'active',selected_start_time=>to_date('10-SEP-18 04:00:00','dd-MON-YY hh24:mi:ss'),selected_end_time=>to_date('10-SEP-18 05:00:00','dd-MON-YY hh24:mi:ss')) from dual;
SQL> spool off
Note in 19c or higher it is better to add "outer_start_time" and "outer_end_time" to get the desired results:
SQL> spool sql_details_history.html
SQL> select dbms_perf.report_perfhub( is_realtime=>0, outer_start_time=>to_date('06-SEP-2022 12:00:00','dd-MON-YYYY hh24:mi:ss'), outer_end_time=>to_date('06-SEP-2022 13:00:00','dd-MON-YYYY hh24:mi:ss'), selected_start_time=>to_date('06-SEP-2022 12:00:00','dd-MON-YYYY hh24:mi:ss'), selected_end_time=>to_date('06-SEP-2022 13:00:00','dd-MON-YYYY hh24:mi:ss')) from dual;
SQL> spool off
3. Using DBMS_AUTO_REPORT from 12c to view SQL Monitoring and Real-time ADDM data that has been captured into AWR.
(i) First identify the report_id containing the monitored SQL during the historical time period from dba_hist_reports view.
Example:
REPORT_ID
=========
1042
(ii) Using the report_id, execute the DBMS_AUTO_REPORT.REPORT_REPOSITORY_DETAIL function to get the historical SQL monitoring for SQL statement(s).
Example:
SQL> spool sql_mon_hist.html
SQL> SELECT DBMS_AUTO_REPORT.REPORT_REPOSITORY_DETAIL(RID => 1042, TYPE => 'html') FROM dual;
SQL> spool off
Please note in the above command that TYPE =>'html' can also be TYPE =>'active', active does provide more detail than html.
Ex:
SELECT /*+ MONITOR */ col1, col2, col3 from table1 where col1=10;
SQL> ALTER SYSTEM SET EVENTS 'sql_monitor [sql:5hc07qvt8v737] force=true';
To disable:
SQL> ALTER SYSTEM SET EVENTS 'sql_monitor [sql:5hc07qvt8v737] off';
Example:
SQL> insert into t1 select /*+ parallel(4) */ * from emp;
SQL> create table t2 as select /*+ parallel(4) */ * from emp;
Once again not all parallel DDLs are monitored.
Example:
SQL> alter table t1 move parallel 4;
The ALTER command though executed in parallel is not monitored.
Comments
Post a Comment