RMAN retention policies allow you to specify how long you want to retain backups. RMAN has two mutually exclusive methods of specifying a retention policy:
- Recovery window
- Number of backups (redundancy)
With a recovery window, you specify a number of days in the past for which you want to be able recover to any point in that window. For example, if you specify a retention policy window of 5 days, then RMAN doesn’t mark as obsolete backups of data files and archive redo logs that are required to be able to restore to any point in that 5-day window:
RMAN> configure retention policy to recovery window of 5 days;
For the specified recovery, RMAN may need backups older than the 5-day window because it may need an older backup to start with to be able to recover to the recovery point specified. For example, suppose your last good backup was made 6 days ago, and now you want to recover to 4 days in the past. For this recovery window, RMAN needs the backup from 6 days ago to restore and recover to the point specified.
You can also specify that RMAN keep a minimum number of backups. For instance, if redundancy is set to 2, then RMAN doesn’t mark as obsolete the latest two backups of data files and archive redo log files:
RMAN> configure retention policy to redundancy 2;
I find that a retention policy based on redundancy is easier to work with and more predictable with regard to how long backups are retained. If I set redundancy to 2, I know that RMAN won’t mark as obsolete the latest two backups. In contrast, the recovery window retention policy depends on the frequency of the backups and the window length to determine whether a backup is obsolete.
Deleting Backups, Based on Retention Policy
You can report on backups that RMAN has determined to be obsolete per the retention policy, as follows:
RMAN> report obsolete;
To delete obsolete backups, run the DELETE OBSOLETE command:
RMAN> delete obsolete;
You’re prompted with this:
Do you really want to delete the above objects (enter YES or NO)?
If you’re scripting the procedure, you can specify the delete not to prompt for input:
RMAN> delete noprompt obsolete;
I usually have the DELETE NOPROMPT OBSOLETE command coded into the shell script that backs up the database. This instructs RMAN to delete any obsolete backups and obsolete archive redo logs, as specified by the retention policy (see the section “Segueing from Decisions to Action,” later in this chapter, for an example of how to automate the deleting of obsolete backups with a shell script).
Clearing the Retention Policy
The default retention policy is redundancy of 1. You can completely disable the RMAN retention policy via the TO NONE command.
RMAN> configure retention policy to none;
When the policy is set to NONE, no backups are ever considered obsolete and therefore cannot be removed via the DELETE OBSOLETE command. This normally is not the behavior you want. You want to let RMAN delete backups per a retention policy based on a window or number of backups.
To set the retention policy back to the default, use the CLEAR command:
RMAN> configure retention policy clear;