Question: I need to understand the
concept of RMAN retention policy settings and the idea of a retention
policy for a specific recovery windows. How does the recovery window
relate to the retention policy?
Answer
(by Aman Sharma): The Recovery Window retention policy doesn't
just keep the last N days of the backup. It calculates the
point-of-recovery (POR) value, accounting the current date and the
number of the days mentioned in the retention policy.
The POR is
more than just the backup of the last N days. In addition, you would
also need the backup of all those which come under the calculation of
POR. For example, assume today is 20th of April (we shall not count year
here since it's not needed) and you decide to go with the Recovery
Window of 2 days.
In the case of non-incremental backup, this is
how it would look:
Current_Date Status
POR
20-April
Available 20-2=18th April
21-April
Available 21-2= 19th April
22-April
Available 22-2=20th April
23-April Backup of 20th Obsoleted 23-2=21st
April
So in the case of 23rd, the backup would be
marked as obsolete.
The same would be true in the case of the
incremental backup as well with one additional layer that now, instead
of just one backup, oracle would consider this also that whether the
backup is a level 0 or level 1 backup and won't consider the backup of
level 1 obsolete if it's still needed for the recovery.
RMAN Recovery Window Retention Policy
It is always important to have backups of the database. In the
same manner, it is also important to delete those backups which
are no longer required for the recovery. RMAN makes the
identification of these backups very easy using retention policy, which governs which backups are safe to be deleted.
Using retention policy, backups are marked as obsolete, which
means not required anymore. There are two possible settings for
retention policy:
- Redundancy
- Recovery window
Redundancystands for the
number of copies that must be available. Once you have the chosen
number of backup copies, any older backups are marked as
obsolete. This does not put any sort of restriction on how long
the backups can be kept. This kind of setting works best for
environments where, depending on the SLA (service level
agreement), some specified number of backup copies must be kept.
By default, this is the setting on which RMAN works, using only
the most current backup copy. Depending on the requirement, the
number of copies can be changed using the configure command like
the following:
RMAN> configure
retention policy to redundancy 2;
In the above example, the redundancy has been set to two. This
means that if you take two backups of your database now, the
oldest copy of the backup would be marked as obsolete.
The other setting, recovery window, is not based on the number
of backup copies, but on the number of days for which you want to
keep the backup. This does not put any condition on the number of
backup copies that can be retained; you can have n number of
copies within the specified period of the recovery window. Any
backup that is older than the recovery window is marked as
obsolete.
In the recovery window, Oracle checks the current backup and
looks for its relevance backwards in time. This is a default set
to seven days which means that the backup must be kept for exactly
seven days, ensuring that you can use it for the recovery within
any point of time for this time period. Any file which does not
come in this range of n days would require a backup to be done for
it and the same would be reported from RMAN as well. To
illustrate the above, look at a hypothetical situation where the
backup is done after every week and the recovery window is also
set for seven days, its default value.
You can see here that the backup is taken every seventh day.
Now assume that you started on July 1st and have taken backups on
the 8th, 15th, 22nd and 29th of July. Assuming the current date is
the 25th of July, according to the recovery window of seven days,
the point of recoverability goes up to the 18th of July. This
means that to ensure the recoverability, the backup taken on 15th
will be kept by Oracle so that you can recover up to that point.
Remember: To be able to recover to the 18th with a database
backup of the 15th, subsequent archived redo logs from the 15th
to the 18th are required.
One interesting part of this type of retention policysetting is that it is not mandatory for RMAN to keep
the backup only for the mentioned number of days. If you have
taken the last level 0 backup and the time period of that exceeds
the recovery window timing, Oracle would have to ensure that it is
not marked as obsolete because just using the level 1 backup will
not guarantee the complete recovery.
The default retention policy is set to a redundancy of 1. You
can change it from its default value by using the configure
command. Note that both
redundancy and recovery window retention policies are mutually
exclusive. Now see what retention policy your database is set to.
You can use the show retention policy command for this:
RMAN> show retention policy;
RMAN configuration parameters are:
configure retention policy to redundancy 1;
So you have the retention policy set to redundancy 1. Change it
to the recovery window of seven days:
RMAN> configure retention policy to
recovery window of 7 days;
old RMAN configuration parameters:
configure retention policy to redundancy 1;
new RMAN configuration parameters:
configure retention policy to recovery window of 7 days;
new RMAN configuration parameters are successfully stored
So now you have the retention policy set to seven days of the
recovery window. In case you want to disable the retention policy
for some reason, you can even do that. Here is how.
configure
retention policy to none;
This would disable the retention policy settings. However,
doing so would stop the report obsolete and delete obsolete
commands from marking any of your previously done backups as
obsolete.