Skip to content

Create AWR Snapshot (snap.sql)

This script creates an immediate AWR (Automatic Workload Repository) snapshot using Oracle’s DBMS_WORKLOAD_REPOSITORY package. AWR snapshots capture point-in-time performance statistics that can be used for analysis, comparison, and troubleshooting. This simple utility is essential for capturing performance data during specific events, before/after changes, or when investigating performance issues that require immediate statistical capture.

EXEC DBMS_WORKLOAD_REPOSITORY.CREATE_SNAPSHOT;
  • Immediate Snapshot Creation: Creates AWR snapshot instantly
  • Performance Data Capture: Captures comprehensive database performance statistics
  • Baseline Establishment: Enables before/after performance comparisons
  • Troubleshooting Support: Provides data for performance issue investigation
  • Simple Execution: Single command execution for ease of use
  • Diagnostic Foundation: Creates foundation for AWR reporting and analysis
@snap.sql

No parameters required - creates snapshot immediately.

EXECUTE on DBMS_WORKLOAD_REPOSITORY
-- Typically requires DBA role or explicit grant
PL/SQL procedure successfully completed.
-- AWR snapshot includes:
-- SQL performance statistics
-- Wait event information
-- System-level metrics
-- Resource utilization data
-- Memory allocation statistics
-- I/O performance metrics
-- Time-based performance data
-- Snapshot data includes:
-- Database instance statistics
-- SQL statement statistics
-- Session and user activity
-- Object access statistics
-- System event information
-- Resource usage patterns
-- Automatic snapshots:
-- Created based on INTERVAL setting (default 1 hour)
-- Managed by AWR automatic collection
-- Consistent baseline data collection
-- Long-term trend analysis support
-- Manual snapshots:
-- Created on-demand for specific analysis
-- Capture data during specific events
-- Support immediate troubleshooting needs
-- Enable precise before/after comparisons
  1. Performance Troubleshooting

    • Capture data during performance issues
    • Create before/after snapshots for changes
    • Support incident investigation
    • Provide data for performance analysis
  2. Change Management

    • Baseline performance before changes
    • Validate performance after changes
    • Support rollback decisions
    • Document change impact
  3. Capacity Planning

    • Capture peak usage statistics
    • Document resource utilization patterns
    • Support infrastructure planning
    • Establish performance baselines
  4. Performance Analysis

    • Create data points for AWR reports
    • Support SQL performance analysis
    • Enable detailed system analysis
    • Provide diagnostic information
-- Create snapshots:
-- Before major system changes
-- During peak usage periods
-- When performance issues occur
-- Before and after maintenance windows
-- During capacity testing
-- Snapshot retention factors:
-- Default retention period (8 days)
-- Storage space requirements
-- Analysis timeframe needs
-- Compliance requirements
-- Generate AWR reports using snapshots:
-- @$ORACLE_HOME/rdbms/admin/awrrpt.sql
-- Specify snapshot range for analysis
-- Compare multiple time periods
-- Analyze performance trends
-- Find available snapshots:
SELECT snap_id, begin_interval_time, end_interval_time
FROM dba_hist_snapshot
WHERE trunc(begin_interval_time) = trunc(sysdate)
ORDER BY snap_id;
-- Optimal timing for snapshots:
-- Capture representative workload periods
-- Avoid backup and maintenance windows
-- Include peak usage periods
-- Consider business cycle timing
-- Manual snapshot frequency:
-- Avoid excessive snapshot creation
-- Balance detail with storage consumption
-- Consider automatic collection adequacy
-- Focus on significant events
-- Snapshot creation impact:
-- Very low performance overhead
-- Quick execution time
-- Minimal resource consumption
-- Safe for production use
-- Resource usage:
-- Small amount of SGA memory
-- Minimal CPU utilization
-- Brief increase in I/O activity
-- Negligible user impact
-- Automated snapshot scripts:
-- Integration with monitoring tools
-- Event-driven snapshot creation
-- Scheduled performance captures
-- Alert-triggered data collection
-- Integration possibilities:
-- Enterprise Manager integration
-- Third-party monitoring tools
-- Custom monitoring scripts
-- Performance management systems
-- Create snapshots when:
-- Performance thresholds exceeded
-- Error conditions detected
-- Resource utilization spikes
-- User complaints received
-- Potential issues:
-- Insufficient privileges
-- Disabled AWR collection
-- Storage space limitations
-- Database state issues
-- Troubleshooting steps:
-- Verify DBA privileges
-- Check AWR configuration
-- Confirm adequate storage
-- Validate database status
-- Check AWR configuration:
SELECT snap_interval, retention
FROM dba_hist_wr_control;
-- Verify AWR is enabled:
SELECT value FROM v$parameter
WHERE name = 'statistics_level';
-- Should be 'TYPICAL' or 'ALL'
-- Optimize AWR settings:
-- Adjust snapshot interval if needed
-- Modify retention period appropriately
-- Configure baseline capture
-- Set appropriate collection level
-- Limit access to authorized personnel:
-- DBA role typically required
-- Monitor snapshot creation activity
-- Audit AWR usage when necessary
-- Implement proper access controls
-- AWR data considerations:
-- Contains performance-sensitive information
-- May include SQL text and bind variables
-- Requires appropriate data protection
-- Consider privacy implications
-- Storage considerations:
-- AWR repository space requirements
-- Snapshot size varies by activity
-- Plan for retention period storage
-- Monitor SYSAUX tablespace usage
-- Regular maintenance:
-- Monitor AWR repository size
-- Purge old snapshots if needed
-- Maintain adequate free space
-- Review retention settings periodically
-- Monitor repository health:
-- Check SYSAUX tablespace space
-- Verify AWR collection status
-- Monitor snapshot creation success
-- Review error logs for issues
-- Create performance baseline:
EXEC DBMS_WORKLOAD_REPOSITORY.CREATE_BASELINE(
start_snap_id => 100,
end_snap_id => 120,
baseline_name => 'PEAK_USAGE_BASELINE',
dbid => (SELECT dbid FROM v$database)
);
-- Compare snapshot periods:
-- Use AWR Compare Period Report
-- Analyze performance differences
-- Identify performance regressions
-- Support change impact analysis
-- Create snapshot during high CPU:
IF (SELECT value FROM v$sysmetric
WHERE metric_name = 'Host CPU Utilization (%)') > 80 THEN
DBMS_WORKLOAD_REPOSITORY.CREATE_SNAPSHOT;
END IF;

This script is essential for:

  1. Performance Troubleshooting - Immediate capture of performance data during issues
  2. Change Management - Creating before/after snapshots to validate change impact
  3. Capacity Planning - Capturing performance data during peak usage periods
  4. Diagnostic Support - Providing foundation data for AWR reports and analysis
  5. Performance Baseline - Establishing reference points for performance comparison