Oracle AWR Snapshots: Query dba_hist_snapshot

Understanding Oracle AWR Snapshot Display

The Oracle Automatic Workload Repository (AWR) is a performance diagnostic tool that collects, processes, and stores database statistics automatically. To generate an AWR report, study a performance trend or troubleshoot a slow period, you first need to know which snapshots exist. This script lists every snapshot in the repository with its snapshot ID, level and start time.

Breakdown of the Code

Query Used:

1set lines 100 pages 999
2select snap_id
3,snap_level
4,to_char(begin_interval_time, 'dd/mm/yy hh24:mi:ss') begin
5from dba_hist_snapshot 
6order by 1
7/

Command Explanation

SQL*Plus Formatting Commands: The script begins with formatting commands that control the output display. The set lines 100 command sets the line width to 100 characters, making the output more readable on standard terminal screens. The pages 999 command sets the page size to 999 lines instead of the default 14, so the column headings print once rather than every 14 lines. If the output runs past 999 lines, the headings repeat at each new page.

SELECT Statement Components: The query retrieves three key columns from the DBA_HIST_SNAPSHOT view. The snap_id column contains the identifier for each snapshot, which is used to reference specific snapshots when generating AWR reports. The snap_level column shows the snapshot level. The to_char(begin_interval_time, 'dd/mm/yy hh24:mi:ss') function converts the snapshot's beginning timestamp into a readable format showing day, month, year, and 24-hour time.

Data Source: The dba_hist_snapshot view is the primary repository for snapshot metadata in Oracle Database. This view stores information about all snapshots captured by AWR, including snapshot IDs, start and end times, database restart information, and snapshot levels. By default, Oracle generates snapshots every hour and retains them for eight days, though these settings can be modified.

Ordering Results: The order by 1 clause sorts the results by the first column (snap_id) in ascending order. This ensures that snapshots are displayed chronologically from oldest to newest, making it easier to identify specific time periods.

Key Points

Snapshot Identification: Each snapshot has a SNAP_ID that identifies it in AWR operations. When generating AWR reports, administrators must specify a beginning and ending snapshot ID to define the analysis period. Statistics views such as DBA_HIST_SYSSTAT carry a SNAP_ID column that joins to DBA_HIST_SNAPSHOT to get the time interval. Not every DBA_HIST_* view has one: the settings view DBA_HIST_WR_CONTROL has no SNAP_ID column.

Snapshot Levels: The snap_level column shows the level recorded for each snapshot.

Time Interval Management: Use the begin_interval_time to pick the right snapshots for analysis. Each snapshot captures statistics from its begin_interval_time to its end_interval_time, a span of one hour with the default settings.

Default Configuration: Oracle Database automatically creates snapshots every 60 minutes and maintains them for 8 days (192 hours). Administrators can change these settings with the DBMS_WORKLOAD_REPOSITORY.MODIFY_SNAPSHOT_SETTINGS procedure or through Oracle Enterprise Manager Cloud Control.

Insights and Practical Applications

Performance Troubleshooting: This script is the first step in a performance investigation. The list of available snapshots shows which snapshot IDs cover the periods of poor performance. Those IDs are the input for generating targeted AWR reports that compare baseline performance with problematic periods.

Report Generation Workflow: Before generating an AWR report, administrators must determine which snapshots bracket the time period of interest. This script provides the snapshot IDs and timestamps needed to make informed selections. For example, if a performance issue occurred between 10:00 AM and 2:00 PM, the administrator would identify the snapshot IDs that encompass this timeframe.

Capacity Planning: Regular review of snapshot availability helps administrators understand their historical data retention. If the oldest snapshot is only three days old instead of the default eight days, check the RETENTION column of DBA_HIST_WR_CONTROL to see the retention setting in force. Administrators can use this information to adjust retention for long-term trend analysis.

Database Restart Detection: When reviewing snapshots, administrators can identify database restarts by looking for a change in the STARTUP_TIME column of DBA_HIST_SNAPSHOT. This information matters when you choose the snapshot range for a report: an AWR report cannot span an instance restart, because cumulative statistics are reset when the instance shuts down, so the begin and end snapshots must come from the same instance startup.

Additional Considerations

Storage Requirements: By default, the AWR repository consumes space in the SYSAUX tablespace; starting with Oracle Database 19c you can store it in another tablespace. A longer retention period takes more space in AWR. Where space is short, shorten the retention period or lengthen the snapshot interval.

Baseline Creation: Snapshots can be preserved indefinitely by creating AWR baselines. Baselines are useful for preserving performance data from important time periods, such as year-end processing or peak business cycles. This allows administrators to compare current performance against historical baselines even after the normal retention period expires.

Manual Snapshot Creation: While Oracle creates snapshots automatically, administrators can also create manual snapshots using the DBMS_WORKLOAD_REPOSITORY.CREATE_SNAPSHOT procedure. Manual snapshots are useful for capturing statistics before and after specific events, such as application deployments or configuration changes.

Common Use Cases

Daily Health Checks: Run this script as part of a daily health check. Snapshots should appear at the configured interval; missing or irregular snapshots point to a problem with AWR collection that needs a closer look.

Performance Analysis Preparation: When performance issues are reported, this script is the starting point. By identifying available snapshot ranges, administrators can proceed directly to generating relevant AWR reports without guessing snapshot IDs.

Documentation and Auditing: For compliance or audit work that needs a record of database performance over a set period, the output shows which snapshots are available for that timeframe.

References

Posts in this series