Oracle RMAN Delete Obsolete - Remove Unneeded Backups

Oracle RMAN Delete Obsolete - Remove Unneeded Backups

The DELETE OBSOLETE command in Oracle RMAN (Recovery Manager) is a powerful maintenance tool that automatically removes backup files that are no longer needed for database recovery. This command helps database administrators manage storage space by deleting backups that fall outside the configured retention policy.

Purpose

The primary purpose of the DELETE OBSOLETE command is to clean up old backups that are no longer required based on your retention policy. RMAN determines which backups are obsolete by comparing them against the configured retention policy, which can be based on either redundancy (number of backups to keep) or a recovery window (time period for point-in-time recovery). When backups become obsolete, they consume valuable storage space without providing additional recovery capabilities.

Code Breakdown

Command

1DELETE OBSOLETE;

This simple command performs three important actions when executed:

  1. Removes physical backup files from the file system or tape storage
  2. Deletes backup entries from the RMAN recovery catalog
  3. Updates control file records to mark the entries as DELETED

Command Syntax Variations

 1-- Basic command (prompts for confirmation)
 2DELETE OBSOLETE;
 3
 4-- Delete without confirmation prompt
 5DELETE NOPROMPT OBSOLETE;
 6
 7-- Delete with custom recovery window
 8DELETE OBSOLETE RECOVERY WINDOW OF 7 DAYS;
 9
10-- Delete with custom redundancy
11DELETE OBSOLETE REDUNDANCY 2;
12
13-- Delete obsolete backups for specific device type
14DELETE OBSOLETE DEVICE TYPE DISK;

Key Points

  • The command uses the retention policy configured in RMAN to determine which backups are obsolete
  • By default, the command prompts for YES/NO confirmation before deleting files
  • The NOPROMPT option allows automated execution in scheduled scripts without manual confirmation
  • RMAN considers both backup files and archived redo logs when determining obsolescence
  • The deletion applies to backups stored on disk, tape, or other configured storage devices
  • Fast Recovery Area (FRA) can automatically overwrite obsolete backups when space is needed
  • You should run CROSSCHECK before DELETE OBSOLETE to ensure the RMAN repository is synchronized with actual files
  • The default retention policy is REDUNDANCY = 1 if not explicitly configured

Understanding Retention Policies

Redundancy-Based Policy

A redundancy-based retention policy specifies how many backup copies RMAN should keep. For example:

1CONFIGURE RETENTION POLICY TO REDUNDANCY 2;

This configuration keeps the two most recent backups of each data file and control file. Any backups beyond this number are considered obsolete.

Recovery Window-Based Policy

A recovery window policy defines a time period for point-in-time recovery. For example:

1CONFIGURE RETENTION POLICY TO RECOVERY WINDOW OF 7 DAYS;

This setting ensures you can recover the database to any point within the last seven days. Backups older than required to support this window are marked obsolete.

Best Practices

Check Current Retention Policy

Before deleting obsolete backups, verify your current retention policy:

1RMAN> SHOW ALL;

Look for the CONFIGURE RETENTION POLICY line in the output.

Report Obsolete Backups First

Always preview which backups will be deleted before executing the delete command:

1RMAN> REPORT OBSOLETE;

This command shows you exactly which backup sets will be removed without actually deleting them.

Run Crosscheck Before Deletion

Crosscheck synchronizes the RMAN repository with the physical backup files:

1RMAN> CROSSCHECK BACKUP;
2RMAN> DELETE OBSOLETE;

This ensures RMAN has accurate information about which files actually exist on disk or tape.

Automate with Scripts

For regular maintenance, include DELETE NOPROMPT OBSOLETE in scheduled backup scripts:

1run {
2  backup database plus archivelog;
3  delete noprompt obsolete;
4}

This approach automatically cleans up old backups after each backup operation completes.

Important Considerations

Obsolete vs Expired Backups

It is important to understand the difference between obsolete and expired backups:

  • Obsolete backups: Files that exist but are no longer needed based on retention policy
  • Expired backups: Files that RMAN expects to exist but cannot find during crosscheck

Use DELETE OBSOLETE for obsolete backups and DELETE EXPIRED for expired backups.

Archive Log Retention

The DELETE OBSOLETE command also removes archived redo logs that are no longer needed. However, you can configure separate retention policies for archive logs if you need to keep them longer than backup files.

Storage Space Management

Running DELETE OBSOLETE regularly helps prevent storage space issues. You can schedule this command to run daily or weekly using operating system scheduling utilities.

Common Use Cases

Daily Backup Cleanup

1RMAN> DELETE NOPROMPT OBSOLETE;

This command is ideal for daily automated cleanup scripts that run after backup operations.

Custom Recovery Window

1RMAN> DELETE OBSOLETE RECOVERY WINDOW OF 10 DAYS;

This overrides the configured retention policy and deletes backups older than 10 days.

Specific Device Type

1RMAN> DELETE OBSOLETE DEVICE TYPE DISK;

This restricts deletion to backups on disk storage only, leaving tape backups unchanged.

Troubleshooting

Command Prompts for Confirmation

If you are running automated scripts and the command waits for input, add the NOPROMPT option:

1DELETE NOPROMPT OBSOLETE;

No Obsolete Backups Found

If RMAN reports no obsolete backups but you expect some, check your retention policy configuration. The policy might be set to NONE or have a very long recovery window.

Retention Policy Set to None

To clear a retention policy set to NONE and restore the default:

1RMAN> CONFIGURE RETENTION POLICY CLEAR;

Performance Impact

The DELETE OBSOLETE command has minimal impact on database performance because it only removes backup files, not database files. However, the deletion process may take time if you have many obsolete backups to remove, especially from tape storage.

Security Considerations

Only database administrators with appropriate RMAN privileges should execute delete commands. Always verify which backups will be deleted using REPORT OBSOLETE before running the delete command to avoid accidentally removing needed backups.

References

Posts in this series