Oracle AWR Manual Snapshot: DBMS_WORKLOAD_REPOSITORY

How to Manually Take an AWR Snapshot in Oracle Database with dbms_workload_repository.create_snapshot

What is Oracle AWR Snapshot Creation?

Creating a manual AWR snapshot in Oracle Database allows database administrators to capture performance statistics at specific points in time, providing precise data for troubleshooting and performance analysis. The DBMS_WORKLOAD_REPOSITORY.CREATE_SNAPSHOT procedure creates an on-demand snapshot outside the automatic hourly collection schedule.

Purpose of Manual AWR Snapshots

Manual AWR snapshots serve several purposes for Oracle database administrators and performance engineers. The primary purpose is to capture database performance metrics during specific time windows that require detailed analysis. Database administrators use manual snapshots when investigating performance issues that occur at irregular intervals or when testing changes before and after implementation. This allows for precise comparison of database behavior during shorter intervals than the default one-hour automatic snapshot period.

Breakdown of the Code

Query:

1exec dbms_workload_repository.create_snapshot

The code consists of a single PL/SQL execution statement that invokes the Oracle built-in procedure for manual snapshot creation. The exec command is a SQL*Plus shorthand for EXECUTE, which runs the PL/SQL procedure immediately. The procedure dbms_workload_repository.create_snapshot belongs to the DBMS_WORKLOAD_REPOSITORY package, which manages all Automatic Workload Repository operations in Oracle Database.

Command Components

The command structure uses the default parameter values when no arguments are specified. The CREATE_SNAPSHOT procedure accepts three optional parameters: flush_level, dbid, and source_name. When executed without parameters, the procedure uses the default flush_level value of 'BESTFIT', which resolves to 'TYPICAL' for non-container databases and CDB root, or 'LITE' for pluggable databases. The procedure returns a snapshot ID number when called as a function, but when executed as shown, it simply creates the snapshot without returning a value.

Key Points

Manual AWR snapshots provide flexibility beyond the automatic hourly collection schedule. Database administrators can create snapshots immediately before and after critical operations like batch jobs, system changes, or performance tests. The snapshots capture performance data including wait events, time model statistics, Active Session History data, system statistics, object usage, and resource-intensive SQL statements. Each snapshot receives a unique identifier that can be queried from the DBA_HIST_SNAPSHOT view after creation.

Flush Levels Explained

Oracle Database supports four flush levels for snapshot creation: BESTFIT, LITE, TYPICAL, and ALL. The BESTFIT level automatically selects the appropriate collection level based on the database type. LITE mode collects only the most important statistics and is the default for pluggable databases and application containers. TYPICAL mode captures most statistics and serves as the default for container database root and non-container databases. ALL mode collects every possible statistic but consumes considerable disk space and takes longer to create.

Privileges and Licensing

In Oracle Database 19c, the DBA role is required to invoke the DBMS_WORKLOAD_REPOSITORY procedures, and the same role is required to run the AWR report scripts. A license for Oracle Diagnostics Pack is also required to use AWR. The CONTROL_MANAGEMENT_PACK_ACCESS parameter records which packs are switched on. Its default is DIAGNOSTIC+TUNING on Enterprise Edition and NONE on all other editions. The DIAGNOSTIC pack covers AWR and ADDM.

AWR collection also depends on the STATISTICS_LEVEL parameter. It must be TYPICAL or ALL. A value of BASIC disables AWR along with many other features. Check both parameters before you rely on a manual snapshot:

1show parameter statistics_level
2show parameter control_management_pack_access

Use Cases and Best Practices

Manual snapshots are particularly valuable when analyzing performance during non-standard time windows. Database administrators should create manual snapshots when troubleshooting specific issues that occur outside the regular hourly intervals. Creating snapshots at the start and end of critical operations enables precise performance analysis of specific database activities. For detailed troubleshooting, administrators can create snapshots at 15-minute intervals to capture more granular performance data.

Verification After Creation

After executing the manual snapshot command, administrators should verify successful creation by querying the DBA_HIST_SNAPSHOT view. The query below displays the snapshot ID, begin interval time, and end interval time for the five most recent snapshots:

1select snap_id, begin_interval_time, end_interval_time
2from dba_hist_snapshot
3order by snap_id desc
4fetch first 5 rows only;

Verification ensures the snapshot was created successfully and provides the snapshot ID needed for generating AWR reports. Database administrators can then use the begin and end snapshot IDs to generate detailed performance reports for the specific time period.

Reading the DBA_HIST_SNAPSHOT Columns

DBA_HIST_SNAPSHOT holds more than the interval times. The columns below tell you how a snapshot was taken and whether it is complete:

  • END_INTERVAL_TIME is the actual time the snapshot was taken, and BEGIN_INTERVAL_TIME is the start of the interval it covers. STARTUP_TIME is the startup time of the instance; a report range that spans two different startup times crosses an instance restart.
  • SNAP_FLAG shows how the row was inserted. 0 is an automatic snapshot from the MMON process, 1 is a manual snapshot created with a PL/SQL package, 2 is an imported snapshot, and 4 is a snapshot taken while the Diagnostic Pack or Tuning Pack was not enabled.
  • SNAP_LEVEL is the snapshot level, and FLUSH_ELAPSED is the time the snapshot took. An ALL snapshot takes a long time to create, and this column shows how long.
  • ERROR_COUNT is the number of errors in the AWR tables for that snapshot. Check it before you use the snapshot as a report boundary.
  • INSTANCE_NUMBER separates the rows of each RAC instance, and DBID identifies the database. You need both values to call the report function.

This query lists only the manual snapshots, newest first:

1select snap_id, dbid, instance_number, end_interval_time,
2       snap_flag, snap_level, flush_elapsed, error_count
3from dba_hist_snapshot
4where snap_flag = 1
5order by snap_id desc
6fetch first 10 rows only;

Generating the Report from Two Snapshots

With a begin and end SNAP_ID, the text report comes from the AWR_REPORT_TEXT pipelined function. It takes the database ID, the instance number, the beginning snapshot ID and the ending snapshot ID, and returns one VARCHAR2(80) column. Replace the four numbers with your own values from the query above:

1select output
2from table(dbms_workload_repository.awr_report_text(1557521192, 1, 5390, 5392));

Oracle recommends the awrrpt.sql script for interactive use, because it prompts for each value. Run it from the SQL*Plus prompt:

1@$ORACLE_HOME/rdbms/admin/awrrpt.sql

Integration with Performance Analysis

Manual snapshots work together with other Oracle performance tools like ADDM and ASH reports. After creating snapshots, the Automatic Database Diagnostic Monitor processes the snapshot data to identify performance bottlenecks and recommend solutions. Database administrators can generate AWR reports using the snapshot IDs to compare performance across different time periods. The combination of manual snapshots and AWR reports shows database performance patterns and issues over time.

Retention and Storage Considerations

AWR snapshots are retained for eight days by default, but administrators can modify this retention period to meet organizational requirements. Oracle notes that the 8-day default covers weekly workload cycles, and that a system with a monthly peak load may need a retention period of one month. For critical time periods, administrators can create AWR baselines that preserve snapshots indefinitely beyond the normal retention period. Longer retention periods consume more disk space in the SYSAUX tablespace, where AWR data is stored by default. Starting with Oracle Database 19c, you can store AWR data in another tablespace to avoid overloading SYSAUX.

The current interval and retention are in DBA_HIST_WR_CONTROL. Both columns are INTERVAL DAY TO SECOND values:

1select dbid, snap_interval, retention, topnsql
2from dba_hist_wr_control;

MODIFY_SNAPSHOT_SETTINGS changes them, and both arguments are in minutes. Retention must fall between 1 day and 100 years, and the interval between 10 minutes and 1 year. A NULL argument keeps the current value. This call keeps 30 days of snapshots (43,200 minutes) and takes one every 30 minutes:

1exec dbms_workload_repository.modify_snapshot_settings(retention => 43200, interval => 30)

Do not set the interval to zero to stop the hourly job. A zero interval disables both automatic and manual snapshots, so CREATE_SNAPSHOT stops working as well.

Syntax Variations

The CREATE_SNAPSHOT procedure can be called with explicit parameters for advanced scenarios. Administrators can specify the flush level explicitly using the syntax EXECUTE DBMS_WORKLOAD_REPOSITORY.CREATE_SNAPSHOT('ALL') to collect all available statistics. When working with pluggable databases or remote databases, the dbid and source_name parameters allow snapshot creation for specific database instances. The function version returns the snapshot ID directly for use in subsequent operations: DBMS_WORKLOAD_REPOSITORY.CREATE_SNAPSHOT RETURN NUMBER.

In SQL*Plus, a bind variable captures that ID so a test script can record its begin and end snapshots without a second query:

1variable begin_snap number
2exec :begin_snap := dbms_workload_repository.create_snapshot
3print begin_snap

Snapshots in a Pluggable Database

Starting with Oracle Database 12c Release 2 (12.2), you can take a snapshot on the CDB root or on an individual PDB. A PDB-level snapshot holds the PDB statistics plus some global statistics. Its snapshot IDs are unique and are not related to the CDB-level snapshot IDs, so do not mix the two when you pick a report range. Automatic snapshots are enabled by default for a CDB but disabled by default for a PDB, and Oracle recommends manual snapshots for a PDB in general. To turn on automatic PDB snapshots, a PDB administrator sets AWR_PDB_AUTOFLUSH_ENABLED to true in that PDB and sets an interval greater than 0.

Common Scenarios

Database administrators commonly create manual snapshots before major system changes to establish a performance baseline. During performance testing, creating snapshots at test boundaries enables accurate measurement of workload impact. When investigating intermittent performance problems, administrators create snapshots when issues occur to capture relevant statistics for later analysis. For batch job monitoring, snapshots taken at job start and completion provide detailed performance metrics for optimization.

Troubleshooting Common Issues

  • No new row in DBA_HIST_SNAPSHOT. Check that STATISTICS_LEVEL is not BASIC and that the DBA_HIST_WR_CONTROL interval is not zero. Either setting stops snapshot creation.
  • Snapshot refused inside a PDB. A CDB administrator can disable AWR for a PDB with a lockdown profile that disables the AWR_ACCESS feature. After that, no snapshot operation works in that PDB.
  • Snapshot fails in restricted session mode. By default, AWR snapshots cannot be created for a database in restricted session mode. The CONTROL_RESTRICTED_SNAPSHOT procedure in the same package changes this.
  • Report call returns nothing useful. Confirm both snapshot rows carry the same DBID and INSTANCE_NUMBER you pass to AWR_REPORT_TEXT, and check ERROR_COUNT for both.
  • Test snapshots fill SYSAUX. Remove a range you no longer need with DROP_SNAPSHOT_RANGE. The ASH data captured in that range is purged at the same time:
1exec dbms_workload_repository.drop_snapshot_range(low_snap_id => 22, high_snap_id => 32)

References

Posts in this series