Watching a Slow Report While It Runs: Real-Time SQL Monitoring on Exadata in Oracle Database@Azure
Most performance tools look backwards. AWR and ASH reports summarise what happened in the last hour, which is useful for trends but frustrating when a report is running right now and the business wants to know whether it will finish before the morning meeting. For a single long-running statement, the most direct tool is Real-Time SQL Monitoring: it shows, line by line in the execution plan, where the statement is spending its time while it runs.
This post follows one slow report on Exadata Database Service in Oracle Database@Azure from the first complaint to the fix. It finds the running statement, reads its plan-line statistics, spots the step where the optimizer's estimate is wrong, checks that Exadata offload still works, and fixes the estimate with extended statistics.
The Use Case
The finance team runs a monthly margin report from Power BI in Azure. It used to take about four minutes. Since a data load last week it runs for about forty minutes, and today it is running again during business hours. Nobody changed the SQL. The DBA needs to know where the time goes before deciding whether to kill it.
Environment used in this runbook
Service: Exadata Database Service on Dedicated Infrastructure in Oracle Database@Azure
Database: Oracle Database 19c (19.24), PDB SALESPDB, two-node RAC
Report user: FIN_REPORTS, connecting through the service sales_reports
Tables: SALES.ORDERS (2.1 billion rows) and SALES.ORDER_ITEMS (8.4 billion rows)
Licence: Real-Time SQL Monitoring is part of the Oracle Tuning Pack, which requires the Diagnostics Pack; both are included in the licence-included Exadata Database Service, but must be licensed separately with Bring Your Own License
How SQL Monitoring Works
Long statements are monitored automatically. Any statement that runs in parallel, or that uses at least five seconds of CPU or I/O in one execution, is monitored without any setting.
Statistics are kept per plan line. For each line of the execution plan, the database records rows produced, executions, time and I/O, refreshed about every second.
Estimates sit next to actuals. The plan's estimated rows can be compared with the rows really produced, which is the quickest way to find a bad cardinality estimate.
Reports can be shared. A text or HTML report captures the whole picture for a colleague or a support request, and recent reports are also kept in the AWR repository.
Step 1: Check That Monitoring Is Allowed
SQL Monitoring needs the Tuning Pack to be enabled in CONTROL_MANAGEMENT_PACK_ACCESS. On Exadata Database Service it usually is, but check it once.
SQL |
-- Connected to SALESPDB as a DBA COLUMN name FORMAT A30 COLUMN value FORMAT A20
SELECT name, value FROM v$parameter WHERE name IN ('control_management_pack_access', 'statistics_level'); |
Expected output |
NAME VALUE
------------------------------ --------------------
statistics_level TYPICAL
control_management_pack_access DIAGNOSTIC+TUNINGWhat to expect: DIAGNOSTIC+TUNING and STATISTICS_LEVEL TYPICAL. With DIAGNOSTIC or NONE, monitoring is switched off, and enabling it is a licensing decision, not only a technical one.
Step 2: Find the Running Report
List the statements that are being monitored right now, with their elapsed time so far. The report is the one running for the finance user.
SQL |
COLUMN sql_id FORMAT A13 COLUMN username FORMAT A12 COLUMN status FORMAT A10
SELECT sql_id, username, status, ROUND(elapsed_time/1e6) AS elapsed_s, ROUND(cpu_time/1e6) AS cpu_s, ROUND(user_io_wait_time/1e6) AS io_s, px_servers_allocated AS px FROM gv$sql_monitor WHERE status = 'EXECUTING' ORDER BY elapsed_time DESC; |
Expected output |
SQL_ID USERNAME STATUS ELAPSED_S CPU_S IO_S PX
------------- ------------ ---------- ---------- ---------- ---------- ----------
9w4kdz3m1qr7t FIN_REPORTS EXECUTING 1742 1688 31 16
5bq2n8xv0hj4c APP_USER EXECUTING 9 4 5What to expect: The finance report has been running for about 29 minutes with 16 parallel servers, and almost all of its time is CPU, not I/O. That already says something: a report that is slow because of I/O would show a large IO_S. Here, the statement is doing too much work in memory, which often means a join handles far more rows than it should.
Step 3: Read the Plan Lines While It Runs
Look at the plan-line statistics of the running statement. Compare the optimizer's estimated rows with the rows each line has produced so far.
SQL |
COLUMN operation FORMAT A34 COLUMN object FORMAT A12
-- Rows are summed over all parallel servers working on each plan line SELECT plan_line_id AS id, LPAD(' ', plan_depth) || plan_operation || ' ' || plan_options AS operation, plan_object_name AS object, MAX(plan_cardinality) AS est_rows, SUM(output_rows) AS act_rows FROM gv$sql_plan_monitor WHERE sql_id = '9w4kdz3m1qr7t' AND status = 'EXECUTING' AND plan_line_id BETWEEN 4 AND 9 GROUP BY plan_line_id, plan_depth, plan_operation, plan_options, plan_object_name ORDER BY plan_line_id; |
Expected output |
ID OPERATION OBJECT EST_ROWS ACT_ROWS
---------- ---------------------------------- ------------ ---------- ----------
4 HASH JOIN 12840 3911752064
5 PX RECEIVE 1204 1688303
6 PX SEND BROADCAST 1204 1688303
7 TABLE ACCESS STORAGE FULL ORDERS 1204 1688303
8 PX BLOCK ITERATOR 8412337 8398120556
9 TABLE ACCESS STORAGE FULL ORDER_ITEMS 8412337 8398120556What to expect: Line 7 is the problem. The optimizer expected 1,204 orders for the month and region, but the scan returns 1.7 million. Because it expected so few rows, it chose to broadcast them to every parallel server and join them with all 8.4 billion order items, which produces almost four billion rows in the hash join. The plan that is fine for 1,204 rows is a disaster for 1.7 million.
Step 4: Save a Text Report
Before deciding anything, capture the full report. It contains the global statistics, the binds, the plan with actuals, and the activity per line, and it can be attached to a ticket or sent to a colleague.
SQL |
SET LONG 1000000 LONGCHUNKSIZE 1000000 LINESIZE 250 PAGESIZE 0 TRIMSPOOL ON SPOOL /tmp/sqlmon_9w4kdz3m1qr7t.txt
SELECT DBMS_SQL_TUNE.REPORT_SQL_MONITOR( sql_id => '9w4kdz3m1qr7t', type => 'TEXT', report_level => 'ALL') FROM dual;
SPOOL OFF |
Expected output |
SQL Monitoring Report
Global Information
------------------------------
Status : EXECUTING
Instance ID : 1
Session : FIN_REPORTS (1873:40215)
SQL ID : 9w4kdz3m1qr7t
SQL Execution ID : 16777219
Execution Started : 11/23/2026 14:51:06
Service : sales_reports
Program : PowerBI.exeWhat this does: It writes the complete monitoring report to a text file on the database server. For a colleague who prefers a graphical view, use type => 'ACTIVE' and spool to an .html file; the file opens in any browser and shows the same data with time lines per plan step.
Tip: Keep the report even if you kill the statement. Monitoring data for finished statements stays in memory only for a limited time, and on a busy system it can be gone within an hour.
Step 5: Check the Exadata Offload
On Exadata, a full scan should be offloaded to the storage cells, so that only the needed columns and rows travel to the database servers. Check that offload works for this statement, so the investigation does not chase the wrong problem.
SQL |
COLUMN sql_id FORMAT A13
SELECT sql_id, ROUND(io_cell_offload_eligible_bytes/1024/1024/1024) AS eligible_gb, ROUND(io_interconnect_bytes/1024/1024/1024) AS interconnect_gb, ROUND(100 * (1 - io_interconnect_bytes / NULLIF(io_cell_offload_eligible_bytes, 0))) AS saved_pct FROM v$sql WHERE sql_id = '9w4kdz3m1qr7t'; |
Expected output |
SQL_ID ELIGIBLE_GB INTERCONNECT_GB SAVED_PCT
------------- ----------- --------------- ----------
9w4kdz3m1qr7t 1240 86 93What to expect: 1,240 GB were eligible for Smart Scan, and only 86 GB crossed the interconnect to the database servers, a saving of 93 percent. The storage side is doing its job. The time goes into the join on the database servers, which confirms what the plan lines showed.
Step 6: Find Why the Estimate Is Wrong
The scan on ORDERS filters on region and status together. After last week's load, most orders for the new region have the same status, so the two columns are strongly correlated, and the optimizer, which multiplies their selectivities, underestimates the result.
SQL |
COLUMN column_name FORMAT A12
SELECT column_name, num_distinct, TO_CHAR(last_analyzed, 'YYYY-MM-DD') AS analyzed FROM dba_tab_col_statistics WHERE owner = 'SALES' AND table_name = 'ORDERS' AND column_name IN ('REGION', 'STATUS', 'ORDER_DATE') ORDER BY column_name; |
Expected output |
COLUMN_NAME NUM_DISTINCT ANALYZED
------------ ------------ ----------
ORDER_DATE 2148 2026-11-16
REGION 14 2026-11-16
STATUS 9 2026-11-16What to expect: Statistics are recent, so this is not a stale-statistics problem. Fourteen regions and nine statuses would give each combination about 1/126 of the rows if they were independent, but in reality almost all rows of the new region share one status. Column group statistics tell the optimizer how the two columns behave together.
Step 7: Create Extended Statistics on the Column Group
Create a column group on REGION and STATUS and gather statistics for it. The optimizer then uses the real number of distinct combinations instead of multiplying the individual selectivities.
SQL |
COLUMN extension FORMAT A32
SELECT DBMS_STATS.CREATE_EXTENDED_STATS('SALES', 'ORDERS', '(REGION,STATUS)') AS extension FROM dual;
BEGIN DBMS_STATS.GATHER_TABLE_STATS( ownname => 'SALES', tabname => 'ORDERS', method_opt => 'FOR COLUMNS (REGION,STATUS) SIZE AUTO', degree => 16); END; / |
Expected output |
EXTENSION
--------------------------------
SYS_STU8QPK2S$PEWHARK2CP3#1F#G
PL/SQL procedure successfully completed.What this does: It adds a hidden virtual column that represents the combination of REGION and STATUS, and gathers statistics, with a histogram if needed, on that combination. New parses of the report now see the correct number of rows for the filter. Cursors already in the shared pool keep their old plan until they are invalidated, which the statistics gathering does by default after a short delay.
Step 8: Run the Report Again and Compare
Ask the finance team to rerun the report, or run it yourself with the same binds, and compare the new execution with the old one in the monitoring list.
SQL |
COLUMN sql_id FORMAT A13 COLUMN status FORMAT A16
SELECT sql_id, sql_exec_id, status, ROUND(elapsed_time/1e6) AS elapsed_s, sql_plan_hash_value AS plan_hash FROM gv$sql_monitor WHERE sql_id = '9w4kdz3m1qr7t' ORDER BY sql_exec_start; |
Expected output |
SQL_ID SQL_EXEC_ID STATUS ELAPSED_S PLAN_HASH
------------- ----------- ---------------- ---------- ----------
9w4kdz3m1qr7t 16777219 DONE (ERROR) 2104 3518246077
9w4kdz3m1qr7t 16777220 DONE (ALL ROWS) 213 1094582736What to expect: The first execution was cancelled by the user after 35 minutes, which shows as DONE (ERROR). The new execution finished in 213 seconds with a different plan. A look at its plan lines shows a hash distribution of both tables instead of a broadcast, with estimated and actual rows now close together on the ORDERS scan.
Step 9: Find Past Reports in AWR
Monitoring data in memory does not last, but since Oracle Database 12c, reports of monitored statements are also saved in the AWR repository. Use them to answer the question "was this report slow last month too?".
SQL |
COLUMN key1 FORMAT A13 COLUMN started FORMAT A16
SELECT report_id, key1, TO_CHAR(period_start_time, 'YYYY-MM-DD HH24:MI') AS started FROM dba_hist_reports WHERE component_name = 'sqlmonitor' AND key1 = '9w4kdz3m1qr7t' ORDER BY period_start_time; |
Expected output |
REPORT_ID KEY1 STARTED
---------- ------------- ----------------
41877 9w4kdz3m1qr7t 2026-10-26 08:02
52390 9w4kdz3m1qr7t 2026-11-23 14:51
52412 9w4kdz3m1qr7t 2026-11-23 15:31What to expect: The October run, the slow run today and the fixed run. DBMS_AUTO_REPORT.REPORT_REPOSITORY_DETAIL with the report ID returns the full saved report, so you can show the finance team the October plan next to today's and explain what changed after the data load.
Summary
Real-Time SQL Monitoring answers the question "what is this statement doing right now?". Check that the Tuning Pack is enabled, list the executing statements in V$SQL_MONITOR, and read V$SQL_PLAN_MONITOR to compare estimated and actual rows per plan line. Save a text or active report before you act, and on Exadata check in V$SQL that Smart Scan offload works, so you look for the problem in the right place. Here the cause was correlated columns, fixed with extended statistics on a column group, and the report dropped from over half an hour to under four minutes. AWR keeps the reports, so the next investigation can start from history.
Comments