Enterprise Diagnostics: AWR, ASH & Wait Events

Enterprise Diagnostics: AWR, ASH & Wait Events in Oracle Database: Senior database performance engineers resolve system bottlenecks not by guessing, but by…

Senior database performance engineers resolve system bottlenecks not by guessing, but by measuring Database Wait Events and analyzing system diagnostic reports.


The Oracle Wait Interface

When a database session issues a request, it is either actively consuming CPU or waiting for a resource. The Oracle Wait Interface categorizes every millisecond of database time:

Wait EventBottleneck CauseResolution Strategy
db file sequential readSingle-block I/O wait (reading through an index)Tune index, verify clustering factor, check SSD latency
db file scattered readMulti-block I/O wait (full table scan reading multiple blocks)Add missing indexes, partition table, increase buffer cache
log buffer spaceLGWR cannot flush redo log buffer quickly enoughMove redo logs to faster storage, increase redo buffer
enq: TX - row lock contentionMultiple sessions attempting to update the same row simultaneouslyFix application commit cadence, resolve transaction locks
latch: cache buffers chainsMultiple sessions contending for the same buffer cache hash bucketAddress hot blocks, partition data

AWR (Automatic Workload Repository)

AWR snapshots database performance metrics every 60 minutes and retains them for 8 days by default. An AWR report compares two snapshots to reveal the top wait events, slowest SQL queries, and hardware saturation:

-- Generate an AWR report for the last 2 hours (run in SQL*Plus or SQL Developer)
-- Invokes the standard Oracle script:
@?/rdbms/admin/awrrpt.sql

-- Inspect active system-wide wait events right now:
SELECT 
    event,
    total_waits,
    time_waited_micro / 1000000 AS seconds_waited,
    wait_class
FROM v$system_event
WHERE wait_class != 'Idle'
ORDER BY time_waited_micro DESC
FETCH FIRST 10 ROWS ONLY;

ASH (Active Session History)

While AWR shows macro-level trends over hours, Active Session History (ASH) samples active sessions every single second into memory buffer V$ACTIVE_SESSION_HISTORY. ASH is designed for diagnosing transient spikes, transient locks, and immediate performance regressions:

-- Identify the exact SQL statements causing the most waits in the last 15 minutes
SELECT 
    sql_id,
    event,
    COUNT(*) AS sample_count,
    ROUND(COUNT(*) * 100.0 / SUM(COUNT(*)) OVER (), 2) AS pct_impact
FROM v$active_session_history
WHERE sample_time > SYSDATE - INTERVAL '15' MINUTE
  AND wait_class != 'Idle'
GROUP BY sql_id, event
ORDER BY sample_count DESC
FETCH FIRST 10 ROWS ONLY;

-- Map the problematic SQL ID back to the actual SQL text
SELECT sql_text FROM v$sql WHERE sql_id = 'a1b2c3d4e5f6g';

Exercises

  1. Query V$SESSION to find all currently blocked sessions and identify the blocking session SID and username.
  2. What is the fundamental difference between an AWR report and an ASH report regarding time resolution?
  3. Explain why the enq: TX - row lock contention wait event is fundamentally an application concurrency design issue rather than a database hardware issue.