Oracle ASH Report: Generate with ashrpt.sql
Generate Active Session History ASH Report in Oracle Database
Users say the application froze for four minutes at 10:42 and then recovered. An hourly AWR report will average that spike away. An Active Session History (ASH) report built for 10:40 to 10:50 shows which sessions, SQL statements and wait events were active in those minutes.
Purpose
ashrpt.sql is the Oracle-supplied script that turns ASH samples into an HTML or text report for a time window you choose. Oracle's tuning guide describes ASH as a tool that "captures transient performance problems by taking samples of active sessions every second and storing the sampled data in a circular buffer in the shared global area (SGA)." A session counts as active when it is waiting for an event that is not in the Idle wait class, so the data grows with the work being done, not with the number of connected sessions.
Run the report when a problem was short, recent and tied to a known time. It answers "what was the database doing between these two times" without tracing set up in advance, because the samples are already being collected.
Code
1-- Generate an ASH report for the local instance (SQL*Plus, as a DBA)
2@?/rdbms/admin/ashrpt.sql
3
4-- Check how far back the samples go before choosing a window
5SELECT MIN(sample_time) AS oldest_in_memory,
6 MAX(sample_time) AS newest_in_memory
7FROM v$active_session_history;
8
9SELECT MIN(sample_time) AS oldest_on_disk
10FROM dba_hist_active_sess_history;
Code Breakdown
The script call
@? is SQL*Plus shorthand for $ORACLE_HOME, so @?/rdbms/admin/ashrpt.sql runs the script from the Oracle home of the database you are connected to. Oracle states that the DBA role is required to run the ASH report scripts.
The prompts
The script is interactive. In the order Oracle documents them, it asks for:
report_type—htmlortext. HTML is easier to read; text is easier to paste into a ticket.begin_time— minutes before the current time, as a negative number.-10starts the report ten minutes ago.duration— minutes from the begin time. Press Enter to accept the default, which runs to the current time.report_name— press Enter for the default name or type your own.
The two retention checks
The two SELECT statements show the range of samples available. V$ACTIVE_SESSION_HISTORY is the in-memory buffer, and SAMPLE_TIME is the time each sample was taken. Because the buffer is circular, old samples are overwritten as new ones arrive, so on a busy system the oldest in-memory sample may be only an hour or two old. Oracle's 2 Day + Performance Tuning Guide notes that AWR snapshot processing "collects the sampled data into memory and writes it to persistent storage"; DBA_HIST_ACTIVE_SESS_HISTORY holds that persisted history. Oracle's tuning guide states that ASH lets you analyse "both current data in the V$ACTIVE_SESSION_HISTORY view and historical data in the DBA_HIST_ACTIVE_SESS_HISTORY view", so a window that has aged out of memory can still be reported from disk. The on-disk copy is thinner: Oracle notes that "only a portion of the session samples is written to disk", so a short spike reported from history shows fewer samples than the same minutes reported from memory. Run both queries before choosing a window, so you know which source covers the minutes you need.
Key Points
- ASH samples active sessions every second; sessions waiting on Idle-class events are not sampled.
- The in-memory buffer is circular, so its time range depends on how busy the instance is.
ashrpti.sqlis the variant for a specific database and instance. It also prompts forslot_width, the seconds per slot in the report's Activity Over Time section.- For Oracle RAC, Oracle documents
ashrpti.sqland notes that only ASH data written to disk is used; that report reads samples found inDBA_HIST_ACTIVE_SESS_HISTORY. - ASH is part of the Diagnostic Pack.
CONTROL_MANAGEMENT_PACK_ACCESSmust includeDIAGNOSTIC; its default isDIAGNOSTIC+TUNINGon Enterprise Edition andNONEon all other editions.
Insights and Best Practices
Read the report in order
Oracle divides the ASH report into eight sections: Top Events, Load Profile, Top SQL, Top PL/SQL, Top Java, Top Sessions, Top Objects/Files/Latches and Activity Over Time. A practical reading order for a short incident:
- Top Events — the top wait events in the sampled activity, split into user, background and priority events. Start here; it tells you what kind of problem you have, such as lock waits, I/O waits or CPU.
- Load Profile — the services, modules, client IDs and SQL command types behind the activity. This is where you learn which application or batch job was responsible.
- Top SQL — the statements that accounted for the most sampled activity. Take the SQL IDs from here into an execution plan check.
- Top Sessions — the sessions that were waiting for a particular wait event, with their share of the activity. One session dominating the list often points to a single stuck job or a blocker.
- Activity Over Time — the window cut into slots, showing how the activity and its top events changed minute by minute. This section shows when a spike started and when it ended.
When Top Events shows row lock waits and Top Sessions shows many sessions waiting behind one, look for the blocking session first. When Top Events shows CPU and Top SQL shows one statement far ahead of the rest, the fix is usually in that statement's plan.
Keep the window tight
Pick the minutes around the incident, not the whole afternoon. A ten-minute window shows the shape of a spike clearly; a three-hour window blends it into everything else.
Use the report targets
ashrpti.sql lets you narrow the report to one target: a session ID, SQL ID, wait class, service, module, action, client ID or PL/SQL entry point. When the problem is one application module, filtering by module removes noise from every other workload.
Pair ASH with AWR
AWR answers "how did this hour compare with last week". ASH answers "what happened in these five minutes". Use the AWR report to find the bad period and the ASH report to explain it.
Mind the licence
ASH data and these reports belong to the Diagnostic Pack. Check that the database is licensed for it before making the report part of a routine runbook.
When to Run This
- A user reports a slowdown at a specific time in the last hour or two.
- An alert fired for a short spike in active sessions or CPU.
- A batch job ran longer than usual and you need to see what it waited on.
- After a tuning change, to confirm the wait profile during the same workload has changed.
Troubleshooting Common Issues
If the report is empty or starts later than the time you asked for, the samples have aged out of memory; run the two retention queries and choose a window inside the range, or rely on the persisted history in DBA_HIST_ACTIVE_SESS_HISTORY. If the script fails on privileges, connect as a user with the DBA role. If ASH views return no rows at all, check CONTROL_MANAGEMENT_PACK_ACCESS: a value of NONE, the default outside Enterprise Edition, disables the Diagnostic Pack features ASH depends on.
References
- Analyzing Sampled Data - Database Performance Tuning Guide - Oracle's guide to ASH,
ashrpt.sql,ashrpti.sql, the prompts, report targets and the RAC report. - Measuring Database Performance - Database Performance Tuning Guide - ASH statistics: current data in memory, historical data on disk, and why only a portion is written to disk.
- V$ACTIVE_SESSION_HISTORY - Oracle Database Reference 19c - Column reference for the in-memory ASH view, including
SAMPLE_TIME. - DBA_HIST_ACTIVE_SESS_HISTORY - Oracle Database Reference 19c - The persisted history of the in-memory ASH buffer.
- CONTROL_MANAGEMENT_PACK_ACCESS - Oracle Database Reference 19c - Which management packs are active, and the default per edition.
- Resolving Transient Performance Problems - 2 Day + Performance Tuning Guide 19c - How AWR snapshot processing persists ASH samples, and running ASH reports from Cloud Control.
- Active Session History (ASH) - oracle-base.com - A worked walkthrough of the ASH views and running
ashrpt.sqlfrom SQL*Plus.
Posts in this series
- Oracle AWR Snapshots: Query dba_hist_snapshot
- Oracle AWR Report Generation Using awrrpt.sql Script
- Oracle AWR Interval and Retention: DBA_HIST_WR_CONTROL
- Oracle AWR Snapshot Interval: modify_snapshot_settings
- Oracle AWR: Change Retention Period to 14 Days
- Oracle AWR Manual Snapshot: DBMS_WORKLOAD_REPOSITORY
- List All Oracle AWR Baselines Using DBA_HIST_BASELINE
- Oracle AWR Baseline with DBMS_WORKLOAD_REPOSITORY
- How to Remove an Oracle AWR Baseline Using DROP_BASELINE
- Oracle: Enable or Disable GATHER_STATS_JOB
- Oracle Time Model Queries: v$sys_time_model Monitoring
- Oracle ASH Report: Generate with ashrpt.sql
- Query Historical ASH Beyond Memory with DBA_HIST_ACTIVE_SESS_HISTORY