Bajwa Consulting Need senior Oracle DBA help? Performance tuning, Cloud migrations, GoldenGate, backup and DR. Plus 70+ free DBA scripts.
Visit bajwaconsulting.com →

Wednesday, January 21, 2015

AWR explained

Originally posted in 2015. Updated November 2026 for Oracle Database 19c and 21c.

Automatic Workload Repository (AWR)

AWR keeps a history of database performance. Every hour (by default) Oracle takes a snapshot of statistics from memory and stores it in the SYSAUX tablespace. AWR reports, ADDM findings and many tuning tools are built on these snapshots.

Each snapshot includes:

  1. Wait events and time model statistics (where database time is spent)
  2. System and session statistics
  3. Top SQL by elapsed time, CPU, I/O and executions
  4. Object statistics, such as segments with the most reads or changes
  5. Active Session History (ASH) samples

First: check your license

AWR, ADDM and ASH are part of the Oracle Diagnostics Pack, a paid option of Enterprise Edition. Running AWR or ADDM reports, or querying the DBA_HIST_* views, counts as using the pack. If the pack is not licensed, that usage can show up in an Oracle license audit.

The CONTROL_MANAGEMENT_PACK_ACCESS parameter records which packs you intend to use:

SHOW PARAMETER control_management_pack_access

-- Licensed for the Diagnostics Pack (and the Tuning Pack):
ALTER SYSTEM SET control_management_pack_access = 'DIAGNOSTIC+TUNING' SCOPE=BOTH;

-- Not licensed: turn the pack features off
ALTER SYSTEM SET control_management_pack_access = 'NONE' SCOPE=BOTH;

Without the Diagnostics Pack, including on Standard Edition, use Statspack (?/rdbms/admin/spcreate.sql), which is free.

Also leave STATISTICS_LEVEL at its default of TYPICAL. Setting it to BASIC stops AWR snapshots.

Snapshot interval and retention

The defaults are a snapshot every 60 minutes, kept for 8 days. Eight days is often too short to compare this week with the same day last month.

-- Current settings
SELECT snap_interval, retention FROM dba_hist_wr_control;

-- Snapshot every 30 minutes, keep 31 days (both values in minutes)
BEGIN
  DBMS_WORKLOAD_REPOSITORY.MODIFY_SNAPSHOT_SETTINGS(
    interval  => 30,
    retention => 31 * 24 * 60);
END;
/

-- Take an extra snapshot by hand, for example before and after a test
EXEC DBMS_WORKLOAD_REPOSITORY.CREATE_SNAPSHOT;

Generating AWR reports

Run these scripts in SQL*Plus. Each one asks for the report type (HTML or text), the number of days to list and the begin and end snapshots.

@?/rdbms/admin/awrrpt.sql     -- current database and instance
@?/rdbms/admin/awrrpti.sql    -- choose a specific DBID and instance (RAC, or a loaded AWR dump)
@?/rdbms/admin/awrgrpt.sql    -- RAC: global report for all instances
@?/rdbms/admin/awrddrpt.sql   -- compare two time periods
@?/rdbms/admin/awrsqrpt.sql   -- one SQL_ID across a snapshot range
@?/rdbms/admin/addmrpt.sql    -- ADDM findings and recommendations

Pick snapshots that tightly surround the problem. A one-hour window around a slowdown tells you far more than a 24-hour average.

CDB and PDB snapshots (19c and 21c)

In a container database, the automatic snapshots are taken in CDB$ROOT and cover the whole CDB. Since 12.2 you can also take snapshots inside each PDB:

-- Connected to the PDB
ALTER SYSTEM SET awr_pdb_autoflush_enabled = TRUE;
EXEC DBMS_WORKLOAD_REPOSITORY.MODIFY_SNAPSHOT_SETTINGS(interval => 60);

When you run awrrpt.sql inside a PDB, it asks whether to use AWR_PDB (the PDB's own snapshots) or AWR_ROOT (the CDB-level data). The matching views are AWR_PDB_*, AWR_ROOT_* and AWR_CDB_*. PDB snapshots also use space, so turn them on only for the PDBs you need to tune.

AWR space in SYSAUX

SELECT occupant_name, ROUND(space_usage_kbytes/1024) AS mb
FROM   v$sysaux_occupants
WHERE  occupant_name IN ('SM/AWR','SM/ADVISOR','SM/OPTSTAT')
ORDER  BY 2 DESC;

-- Full breakdown of what AWR stores
@?/rdbms/admin/awrinfo.sql

If SYSAUX is filling up, shorten the retention first. To remove a range of old snapshots right away:

-- List snapshots, then drop the oldest range
SELECT MIN(snap_id), MAX(snap_id) FROM dba_hist_snapshot;

EXEC DBMS_WORKLOAD_REPOSITORY.DROP_SNAPSHOT_RANGE(low_snap_id => 1000, high_snap_id => 1200);

Keep any snapshots you may still need. A baseline (DBMS_WORKLOAD_REPOSITORY.CREATE_BASELINE) keeps a known-good period from being purged, so you can compare against it later.

Related post

SQL plan baselines also live in SYSAUX. See my updated post on SQL Plan Management (cleanup of SYSAUX) on this blog.

More current DBA scripts are in my GitHub repository: github.com/sbajwa55/dba-scripts. For help with Oracle performance, migrations or AWS, visit Bajwa Consulting Services.

No comments:

Post a Comment