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 Event | Bottleneck Cause | Resolution Strategy |
|---|---|---|
db file sequential read | Single-block I/O wait (reading through an index) | Tune index, verify clustering factor, check SSD latency |
db file scattered read | Multi-block I/O wait (full table scan reading multiple blocks) | Add missing indexes, partition table, increase buffer cache |
log buffer space | LGWR cannot flush redo log buffer quickly enough | Move redo logs to faster storage, increase redo buffer |
enq: TX - row lock contention | Multiple sessions attempting to update the same row simultaneously | Fix application commit cadence, resolve transaction locks |
latch: cache buffers chains | Multiple sessions contending for the same buffer cache hash bucket | Address 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
- Query
V$SESSIONto find all currently blocked sessions and identify the blocking session SID and username. - What is the fundamental difference between an AWR report and an ASH report regarding time resolution?
- Explain why the
enq: TX - row lock contentionwait event is fundamentally an application concurrency design issue rather than a database hardware issue.