Skip to content

Commit 7266591

Browse files
Merge pull request #323 from oracle-devrel/Ulrike-sqlmonitor
Ulrike SQL Monitor entries for the technology Real-time SQL monitoring
2 parents 5c88006 + cf635fe commit 7266591

File tree

10 files changed

+167
-0
lines changed

10 files changed

+167
-0
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Real-Time SQL Monitoring
2+
3+
Oracle provides a series of advisors to analyze the database in different fields, e.g. to examine appropriate access structures, to decide on security configurations, segment compression and so on. They provide the basis for automations within the Oracle Database and support DBAs and database developers when working with the Oracle Database.
4+
Advisors are distinguished by certain characteristics and are usually available through different methods: Graphical tools such as Oracle Enterprise Manager Cloud Control or SQL Developer, scripts through PL/SQL packages, initialization parameters or through corresponding v$ views. Most of them are available without additional installation and can be used immediately. Others can be loaded separately from My Oracle Support (MOS) or can be activated and used via Cloud Console. Unlike alerts, advisors are more resource intensive, as their analysis and suggested solutions have a greater level of detail. It is important to know how to use advisors and what advice to expect.
5+
As the database and database offering evolves, new advisors and automations are continually made available.
6+
7+
8+
## Useful Links
9+
10+
### Documentation
11+
12+
- [PL/SQL Packages and Types Reference DBMS_SQL_MONITOR](https://docs.oracle.com/en/database/oracle/oracle-database/19/arpls/DBMS_SQL_MONITOR.html#GUID-13874A73-369E-42CD-9C43-A12F1B3BDEC6)
13+
- [PL/SQL Packages and Types Reference DBMS_SQLTUNE](https://docs.oracle.com/en/database/oracle/oracle-database/23/arpls/DBMS_SQLTUNE.html#GUID-CFA1F851-1FC1-44D6-BB5C-76C3ADE1A483)
14+
- [PL/SQL Packages and Types Reference DBMS_PERF](https://docs.oracle.com/en/database/oracle/oracle-database/19/arpls/DBMS_PERF.html#GUID-290C18B9-A2EF-468D-9D6E-B31D717082BB)
15+
- [Database Reference V$SQL_MONITOR](https://docs.oracle.com/en/database/oracle/oracle-database/19/refrn/V-SQL_MONITOR.html#GUID-79E97A84-9C27-4A5E-AC0D-C12CB3E748E6)
16+
17+
### Team Publications
18+
19+
- [Real-Time SQL Monitoring: a MUST for SQL Tuning](https://blogs.oracle.com/coretec/post/oracle-database-real-time-sql-monitoring-one-of-the-most-important-tools)
20+
21+
22+
### Blogs and technical briefs
23+
24+
- [Getting the most out of Oracle SQL Monitor](https://sqlmaria.com/2017/08/01/getting-the-most-out-of-oracle-sql-monitor/)
25+
- [Real-Time SQL Monitoring and Oracle Database In-Memory](https://www.oracle.com/a/ocom/docs/database/sql-monitor-brief.pdf)
26+
27+
28+
# License
29+
30+
Copyright (c) 2023 Oracle and/or its affiliates.
31+
32+
Licensed under the Universal Permissive License (UPL), Version 1.0.
33+
34+
See LICENSE for more details.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#scripts-for-sql-tuning-monitoring
2+
3+
These scripts can be used to generate Real-Time SQL monitoring reports in HTML or ACTIVE HTML.
4+
5+
##scripts
6+
7+
- active-report.sql: Generate an active html report with DBMS_SQL_MONITOR.REPORT_SQL_MONITOR
8+
9+
- dbresource-manager.sql: Real-Time SQL Monitoring when Database Resource Manager is in use
10+
11+
- find-sqlid.sql: Find SQL id with V$SQL_MONITOR
12+
13+
- html-report.sql: Generate a report in HTML with DBMS_SQL_MONITOR.REPORT_SQL_MONITOR
14+
15+
- report-for-devs.sql: DBMS_SQLTUNE for database developers to view the last monitored statement executed by the user
16+
17+
- report-summary-for-devs.sql: DBMS_SQLTUNE for database developers to get a list of all statements executed by the user
18+
19+
- report-with-sqlid.sql: Generate a report with DBMS_SQL_MONITOR.REPORT_SQL_MONITOR for a specific statement
20+
21+
- session-longops.sql: Example for V$SESSION_LONGOPS usage
22+
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
REM Script: active-report.sql
2+
REM Generate active (HTML) report with DBMS_SQL_MONITOR.REPORT_SQL_MONITOR
3+
4+
-- report on the last statement monitored by Oracle
5+
-- please use the proposed SQL*Plus formats here to get the correct report output
6+
7+
set trimspool on
8+
set trim on
9+
set pagesize 0
10+
set linesize 32767
11+
set long 1000000
12+
set longchunksize 1000000
13+
14+
spool sqlmon_active.html
15+
16+
select dbms_sql_monitor.report_sql_monitor(report_level=>'ALL',type=>'ACTIVE')
17+
from dual;
18+
19+
spool off
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
REM Script: dbresource-manager.sql
2+
REM Database Resource Manager and Real-Time SQL Monitoring
3+
4+
-- query columns with rm_ prefix to get database resource manager information
5+
6+
SELECT username, elapsed_time, plsql_exec_time, sql_text, cpu_time,
7+
rm_last_action, rm_last_action_reason, rm_last_action_time, rm_consumer_group
8+
FROM v$sql_monitor WHERE username is not null;
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
REM Script: find-sqlid.sql
2+
REM Find SQL id with V$SQL_MONITOR
3+
4+
-- display text, sql id and cpu time
5+
SELECT distinct s.sql_text, m.sql_id, m.cpu_time
6+
FROM v$sql_monitor m INNER JOIN v$sql s ON s.sql_id=m.sql_id
7+
ORDER BY m.cpu_time;
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
REM Script: html-report.sql
2+
REM Generate HTML report with DBMS_SQL_MONITOR.REPORT_SQL_MONITOR
3+
4+
-- report on the last statement monitored by Oracle
5+
-- please use the proposed SQL*Plus formats here to get the correct HTML report
6+
7+
set trimspool on
8+
set trim on
9+
set pagesize 0
10+
set linesize 32767
11+
set long 1000000
12+
set longchunksize 1000000
13+
spool sqlmon_active.html
14+
15+
SELECT dbms_sql_monitor.report_sql_monitor(type => 'HTML', report_level => 'ALL')
16+
FROM dual;
17+
18+
spool off
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
REM Script: report-for-devs.sql
2+
REM DBMS_SQLTUNE for database developers
3+
4+
-- DBMS_SQLTUNE contains the REPORT_SQL_MONITOR and REPORT_SQL_MONITOR_LIST functions
5+
-- list the last monitored statement excuted by the user with REPORT_SQL_MONITOR
6+
-- enter value for type (e.g. TEXT, HTML, ACTIVE)
7+
-- please use the proposed SQL*Plus formats
8+
9+
set trimspool on
10+
set trim on
11+
set pagesize 0
12+
set linesize 32767
13+
set long 1000000
14+
set longchunksize 1000000
15+
16+
SELECT dbms_sqltune.report_sql_monitor(type => '&type') FROM dual;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
REM Script: report-summary-for-devs.sql
2+
REM DBMS_SQLTUNE for database developers for all statements executed by the user
3+
4+
-- list all monitored statement executed by the user
5+
-- enter value for type (e.g. TEXT, HTML, ACTIVE)
6+
-- use the proposed SQL*Plus formats to get a correct report output
7+
8+
set trimspool on
9+
set trim on
10+
set pagesize 0
11+
set linesize 32767
12+
set long 1000000
13+
set longchunksize 1000000
14+
15+
select DBMS_SQLTUNE.REPORT_SQL_MONITOR_LIST(type=>'TEXT') from dual;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
REM Script: report-with-sqlid.sql
2+
REM Report generation with DBMS_SQL_MONITOR.REPORT_SQL_MONTOR
3+
4+
-- optional: find SQL id with find-sqlid.sql
5+
-- enter SQL id and type (e.g. TEXT, ACTIVE, HTML)
6+
7+
set trimspool on
8+
set trim on
9+
set pagesize 0
10+
set linesize 32767
11+
set long 1000000
12+
set longchunksize 1000000
13+
spool sqlmon_active.html
14+
15+
SELECT dbms_sql_monitor.report_sql_monitor(sql_id=> '&SQLid', type => '&type', report_level => 'ALL')
16+
FROM dual;
17+
18+
spool off
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
REM Script: session-longops.sql
2+
REM Example for V$SESSION_LONGOPS
3+
4+
5+
-- V$SESSION_LONGOPS displays the status of various operations that run for longer than 6 seconds (in absolute time)
6+
7+
SELECT opname, username, sql_fulltext, to_char(start_time,'DD-MON-YYYY HH24:MI:SS'),
8+
(sofar/totalwork)*100 "%_complete", time_remaining, s. con_id
9+
FROM v$session_longops s INNER JOIN v$sql sl USING (sql_id)
10+
WHERE time_remaining > 0;

0 commit comments

Comments
 (0)