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 — html or text. HTML is easier to read; text is easier to paste into a ticket.
  • begin_time — minutes before the current time, as a negative number. -10 starts 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.sql is the variant for a specific database and instance. It also prompts for slot_width, the seconds per slot in the report's Activity Over Time section.
  • For Oracle RAC, Oracle documents ashrpti.sql and notes that only ASH data written to disk is used; that report reads samples found in DBA_HIST_ACTIVE_SESS_HISTORY.
  • ASH is part of the Diagnostic Pack. CONTROL_MANAGEMENT_PACK_ACCESS must include DIAGNOSTIC; its default is DIAGNOSTIC+TUNING on Enterprise Edition and NONE on 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

Posts in this series