Overview
The Automatic Workload Repository (AWR) stores periodic snapshots of performance statistics (by default hourly, kept eight days). Active Session History (ASH) samples active sessions every second in memory (V$ACTIVE_SESSION_HISTORY) and persists a subset (DBA_HIST_ACTIVE_SESS_HISTORY). ADDM analyses a snapshot pair and recommends fixes. Together they are Oracle’s equivalent of wait statistics plus Query Store (sqlserver-wait-stats, sqlserver-query-store).
AWR, ASH and ADDM belong to the Diagnostics Pack, which requires a license in Enterprise Edition. In the Free build used here control_management_pack_access = DIAGNOSTIC+TUNING. Without the pack use Statspack, which is free.
Core concepts
- DB Time is the total time sessions spend in database calls (CPU plus non-idle waits). The central question of Oracle tuning is where DB Time goes, an idea shared with sqlserver-wait-stats.
- An AWR report has these sections: Load Profile (per-second and per-transaction rates), Top Foreground Events, Time Model Statistics, SQL ordered by Elapsed Time / CPU / Gets / Reads, Instance Activity, tablespace and file I/O.
- Take manual snapshots around a test:
DBMS_WORKLOAD_REPOSITORY.CREATE_SNAPSHOT. Reports:awr_report_text(dbid, inst, begin_snap, end_snap)or@?/rdbms/admin/awrrpt.sql. - ASH answers “what was happening at 14:03?”: group samples by
sql_id,event,session_id,blocking_sessionfor any interval, with one-second granularity. - In a CDB, snapshots are taken in the root; reading them from the PDB needs PDB-level AWR enabled, otherwise you get
ORA-20020: Database/Instance/Snapshot mismatch.
Worked example
On the Free container: snapshot, run a workload (60 filtered scans plus 20,000 indexed lookups), snapshot again, report from the root:
EXEC DBMS_WORKLOAD_REPOSITORY.CREATE_SNAPSHOT;
-- ... workload in FREEPDB1 ...
EXEC DBMS_WORKLOAD_REPOSITORY.CREATE_SNAPSHOT;
SELECT output FROM TABLE(DBMS_WORKLOAD_REPOSITORY.AWR_REPORT_TEXT(:dbid, 1, :begin_snap, :end_snap));Extract of the report (about 3,100 lines):
Load Profile Per Second Per Transaction
DB Time(s): 1.0 4.2
DB CPU(s): 0.8 3.6
Redo size (bytes): 1,041,334 4,533,968
Logical read (blocks): 156,104 679,678
Physical read (blocks): 180 784
Top 10 Foreground Events Waits Time(s) % DB wait time
DB CPU 3.6 87.2
enq: CR - block range reuse ck 27 .3 6.4
direct path write 44 .1 3.1
log file switch completion 1 .1 2.4CPU dominates, which fits a workload of logical reads. The top SQL by elapsed time was the PL/SQL block that ran the workload (1.3 s). v$active_session_history held 45 rows after the first minutes of testing.
Pitfalls and production notes
- Compare two snapshots from similar periods; a report over a whole day hides spikes (use a 15-30 minute window).
- Do not stop at the top event: map it to the SQL (ASH,
SQL ordered by) and the plan (oracle-execution-plans). - Increase snapshot frequency (for example 15 minutes) and retention (for example 30 days) on busy systems; AWR space is in
SYSAUX. - A short
awr_diff_report_textbetween a good and a bad period is the fastest way to find a regression. - Alert on the average active sessions (DB Time / elapsed) compared with CPU count (2 in this container).
Practice questions
- What does DB Time / elapsed time represent?
- How do you find the SQL behind an
enq: TX - row lock contentionwait at 02:10? - Why does the report contain internal “Replication SQL” or snapshot calls, and how do you ignore them?
References
- Oracle Database Performance Tuning Guide, Automatic Performance Statistics; Active Session History
Related
oracle-execution-plans · oracle-locking-concurrency · sqlserver-wait-stats · pg-monitoring