Deleting Archive Log files in a Data Guard environment
Published on: Author: Bastiaan Bak Category: OracleWe recently configured an Oracle 12.2 database environment with a primary database, and a physical standby database managed by Oracle Data Guard.
The backup on the primary database removed all archive log files after a successful backup. For a normal standalone database this is a common configuration, but in a Data Guard environment this is not sufficient.
What will happen if your standby database is unavailable? Before you delete any files on the primary database, you should be sure you no longer need them for the recovery of the standby database.
Initial configuration
When you use the Data Guard Broker for the configuration of your standby database, it will create a remote archive destination on the primary, connecting to a service on the standby database:
SQL> SHOW parameter log_archive_dest_2 NAME TYPE VALUE ------------------------------------ ----------- ------------------------------ log_archive_dest_2 string service="motdc1", ASYNC NOAFFI RM delay=0 optional compressio n=disable max_failure=0 max_co nnections=1 reopen=300 db_uniq ue_name="motdc1" net_timeout=3 0, valid_for=(online_logfile,a ll_roles)
We scheduled backups on both the primary and the standby database. Part of the RMAN backup script was the cleanup of all archive log files after a day, if there was a successful backup:
backup as compressed backupset archivelog all not backed up; delete noprompt archivelog until time 'sysdate - 1' backed up 1 times to device type disk;
When to remove archive log files?
Our backup script was not really bulletproof. Although we kept our archive log files for at least a day, this is not really what we wanted. The files should only be removed after we are sure all transaction had been successfully applied to the standby database.
When querying the v$archived_log view for log_archive_dest_2 we can check what files are applied on the standby:
select dest_id , sequence# , applied from v$archived_log where dest_id = 2 and sequence# > ( select max(sequence#) - 10 from v$archived_log ) order by sequence# / DEST_ID SEQUENCE# APPLIED ---------- ---------- --------- 2 1912 YES 2 1913 YES 2 1914 YES 2 1915 YES 2 1916 YES 2 1917 YES 2 1918 YES 2 1919 YES 2 1920 YES 2 1921 NO 10 rows selected.
Why not let Oracle handle it?
Rather than changing the backup script it might be easier to let the database handle it. All files in the FRA could be managed by the database.
The documentation describes how we can configure automatic cleanup policy of the archive log files after they are applied on the standby database. We changed this setting in the RMAN backup configuration, and also removed the delete statement from the backup script.
Testing
After changing the RMAN configuration...
RMAN> CONFIGURE ARCHIVELOG DELETION POLICY TO APPLIED ON ALL STANDBY ; old RMAN configuration parameters: CONFIGURE ARCHIVELOG DELETION POLICY TO NONE; new RMAN configuration parameters: CONFIGURE ARCHIVELOG DELETION POLICY TO APPLIED ON ALL STANDBY; new RMAN configuration parameters are successfully stored starting full resync of recovery catalog full resync complete RMAN>
...and doing some log switches...
SQL> ALTER system switch logfile ; System altered. SQL> ALTER system switch logfile ; System altered. SQL> ALTER system switch logfile ; System altered.
...we made another archive backup:
RMAN> backup as compressed backupset archivelog all not backed up;
I first expected that the archive log files would have been removed at the moment of the backup, but this was not the case. The files were still in the FRA.
Maybe the files were not applied to the standby database? I checked the v$archived_log view again, but all the files - except the current - had been applied to the standby.
SQL> SELECT dest_id , SEQUENCE# , applied FROM v$archived_log WHERE dest_id = 2 AND SEQUENCE# > ( SELECT MAX(SEQUENCE#) - 10 FROM v$archived_log ) ORDER BY SEQUENCE# / 2 3 4 5 6 DEST_ID SEQUENCE# APPLIED ---------- ---------- --------- 2 1930 YES 2 1931 YES 2 1932 YES 2 1933 YES 2 1934 YES 2 1935 YES 2 1936 YES 2 1937 YES 2 1938 YES 2 1939 NO 10 ROWS selected.
This was not really doing what I expected, so back to the documentation: “For primary databases, the archived redo log files are eligible for deletion after they are applied on the standby.” So, the files are not deleted immediately, but they are eligible for deletion.
You can check this in the V$RECOVERY_AREA_USAGE view. We can see that some space for “Archived Log” is reclaimable, so eligible for deletion:
SQL> SELECT FILE_TYPE , PERCENT_SPACE_USED , PERCENT_SPACE_RECLAIMABLE , NUMBER_OF_FILES 2 FROM V$RECOVERY_AREA_USAGE 3 / FILE_TYPE PERCENT_SPACE_USED PERCENT_SPACE_RECLAIMABLE NUMBER_OF_FILES ----------------------- ------------------ ------------------------- --------------- CONTROL FILE 0 0 0 REDO LOG 0 0 0 ARCHIVED LOG .43 .43 13 BACKUP PIECE 0 0 0 IMAGE COPY 0 0 0 FLASHBACK LOG 65.63 0 6 FOREIGN ARCHIVED LOG 0 0 0 AUXILIARY DATAFILE COPY 0 0 0 8 ROWS selected.
After more load on the database the FRA fills up to 85%, and this triggers a warning in the alert log:
2017-11-06T17:36:12.303898+01:00 Errors in file /oraclebase/db/diag/rdbms/motdc2/motdc2/trace/motdc2_m000_24332.trc: ORA-19815: WARNING: db_recovery_file_dest_size of 17179869184 bytes is 87.50% used, and has 2147470336 remaining bytes available. 2017-11-06T17:36:12.308765 +01:00 ************************************************************************ You have following choices to free up space from recovery area: 1. Consider changing RMAN RETENTION POLICY. If you are using Data Guard, then consider changing RMAN ARCHIVELOG DELETION POLICY. 2. Back up files to tertiary device such as tape using RMAN BACKUP RECOVERY AREA command. 3. Add disk space and increase db_recovery_file_dest_size parameter to reflect the new space. 4. Delete unnecessary files using RMAN DELETE command. If an operating system command was used to delete files, then use RMAN CROSSCHECK and DELETE EXPIRED commands. ************************************************************************
This warning gives some suggestions on how to fix this issue. The first one is a bit strange. If we use Data Guard, we should consider changing the RMAN ARCHIVELOG DELETION POLICY. I think this is what we just did...
A little later the backup triggers another log switch, and we see more messages in the alert log. The database removes the oldest archive log files:
Deleted Oracle managed file /orafra/db/MOTDC2/archivelog/2017_11_06/o1_mf_1_1927_f00bl4x2_.arc Deleted Oracle managed file /orafra/db/MOTDC2/archivelog/2017_11_06/o1_mf_1_1928_f00cynk7_.arc Deleted Oracle managed file /orafra/db/MOTDC2/archivelog/2017_11_06/o1_mf_1_1929_f00hh2z4_.arc Deleted Oracle managed file /orafra/db/MOTDC2/archivelog/2017_11_06/o1_mf_1_1930_f00lzlvm_.arc Deleted Oracle managed file /orafra/db/MOTDC2/archivelog/2017_11_06/o1_mf_1_1931_f00pj2n2_.arc Deleted Oracle managed file /orafra/db/MOTDC2/archivelog/2017_11_06/o1_mf_1_1932_f00t0ltc_.arc Deleted Oracle managed file /orafra/db/MOTDC2/archivelog/2017_11_06/o1_mf_1_1933_f00xk2p8_.arc Deleted Oracle managed file /orafra/db/MOTDC2/archivelog/2017_11_06/o1_mf_1_1934_f0111ltx_.arc
So, the automatic cleanup works, but only after space pressure in the FRA removes the files marked as eligible for deletion, as explained in the documentation. And the definition of space pressure seems to be an 85% usage of the FRA, which might trigger an ORA-19815 warning.
Back to manual cleanup?
Although the solution above does what it should do, I’m not really happy with this. The files are not really removed after being applied on the standby as the configuration suggests, and more serious; the ORA-19815 warning could trigger a daily monitoring alarm on a perfectly working database.
A good solution seems to be the configuration of the delete policy in RMAN, in combination with a daily “delete noprompt archivelog all” in the backup script.
For testing we first configure the policy:
CONFIGURE ARCHIVELOG DELETION POLICY TO APPLIED ON ALL STANDBY;
Then, in the data guard manager, we stop the apply on the standby database:
DGMGRL> edit database motdc1 set state='apply-off' ; Succeeded.
After that, we make some log switches:
SQL> ALTER system switch logfile ; System altered. SQL> ALTER system switch logfile ; System altered. SQL> ALTER system switch logfile ; System altered.
We can check that the new archives are not applied on the standby database:
SQL> SELECT dest_id , SEQUENCE# , applied FROM v$archived_log WHERE dest_id = 2 AND SEQUENCE# > ( SELECT MAX(SEQUENCE#) - 10 FROM v$archived_log ) ORDER BY SEQUENCE# / DEST_ID SEQUENCE# APPLIED ---------- ---------- --------- 2 1940 YES 2 1941 YES 2 1942 YES 2 1943 YES 2 1944 YES 2 1945 YES 2 1946 YES 2 1947 NO 2 1948 NO 2 1949 NO 10 ROWS selected.
Next, we make a backup in RMAN:
RMAN> backup as compressed backupset archivelog all not backed up; Starting backup at 06-NOV-17 current log archived using channel ORA_DISK_1 using channel ORA_DISK_2 using channel ORA_DISK_3 using channel ORA_DISK_4 skipping archived logs of thread 1 from sequence 1945 to 1946; already backed up channel ORA_DISK_1: starting compressed archived log backup set channel ORA_DISK_1: specifying archived log(s) in backup set input archived log thread=1 sequence=1947 RECID=4426 STAMP=959363627 channel ORA_DISK_1: starting piece 1 at 06-NOV-17 channel ORA_DISK_2: starting compressed archived log backup set channel ORA_DISK_2: specifying archived log(s) in backup set input archived log thread=1 sequence=1950 RECID=4432 STAMP=959363700 channel ORA_DISK_2: starting piece 1 at 06-NOV-17 channel ORA_DISK_3: starting compressed archived log backup set channel ORA_DISK_3: specifying archived log(s) in backup set input archived log thread=1 sequence=1948 RECID=4428 STAMP=959363642 channel ORA_DISK_3: starting piece 1 at 06-NOV-17 channel ORA_DISK_4: starting compressed archived log backup set channel ORA_DISK_4: specifying archived log(s) in backup set input archived log thread=1 sequence=1949 RECID=4430 STAMP=959363644 channel ORA_DISK_4: starting piece 1 at 06-NOV-17 channel ORA_DISK_2: finished piece 1 at 06-NOV-17 piece handle=/orarman/db/MOTDC2/gnsitejl_1_1.bck tag=TAG20171106T175500 comment=NONE channel ORA_DISK_2: backup set complete, elapsed time: 00:00:00 channel ORA_DISK_1: finished piece 1 at 06-NOV-17 piece handle=/orarman/db/MOTDC2/gmsitejl_1_1.bck tag=TAG20171106T175500 comment=NONE channel ORA_DISK_1: backup set complete, elapsed time: 00:00:00 channel ORA_DISK_3: finished piece 1 at 06-NOV-17 piece handle=/orarman/db/MOTDC2/gositejl_1_1.bck tag=TAG20171106T175500 comment=NONE channel ORA_DISK_3: backup set complete, elapsed time: 00:00:00 channel ORA_DISK_4: finished piece 1 at 06-NOV-17 piece handle=/orarman/db/MOTDC2/gpsitejl_1_1.bck tag=TAG20171106T175500 comment=NONE channel ORA_DISK_4: backup set complete, elapsed time: 00:00:00 Finished backup at 06-NOV-17 Starting Control File and SPFILE Autobackup at 06-NOV-17 piece handle=/orarman/db/MOTDC2/c-390140924-20171106-10 comment=NONE Finished Control File and SPFILE Autobackup at 06-NOV-17 RMAN>
And, as part of the backup procedure, we try to delete the archivelog files:
RMAN> delete noprompt archivelog all backed up 1 times to device type disk; released channel: ORA_DISK_1 released channel: ORA_DISK_2 released channel: ORA_DISK_3 released channel: ORA_DISK_4 allocated channel: ORA_DISK_1 channel ORA_DISK_1: SID=2822 device type=DISK allocated channel: ORA_DISK_2 channel ORA_DISK_2: SID=4234 device type=DISK allocated channel: ORA_DISK_3 channel ORA_DISK_3: SID=4467 device type=DISK allocated channel: ORA_DISK_4 channel ORA_DISK_4: SID=4705 device type=DISK RMAN-08120: warning: archived log not deleted, not yet applied by standby archived log file name=/orafra/db/MOTDC2/archivelog/2017_11_06/o1_mf_1_1946_f014trpk_.arc thread=1 sequence=1946 RMAN-08120: warning: archived log not deleted, not yet applied by standby archived log file name=/orafra/db/MOTDC2/archivelog/2017_11_06/o1_mf_1_1947_f014wv4x_.arc thread=1 sequence=1947 RMAN-08120: warning: archived log not deleted, not yet applied by standby archived log file name=/orafra/db/MOTDC2/archivelog/2017_11_06/o1_mf_1_1948_f014xblo_.arc thread=1 sequence=1948 RMAN-08120: warning: archived log not deleted, not yet applied by standby archived log file name=/orafra/db/MOTDC2/archivelog/2017_11_06/o1_mf_1_1949_f014xdo5_.arc thread=1 sequence=1949 RMAN-08120: warning: archived log not deleted, not yet applied by standby archived log file name=/orafra/db/MOTDC2/archivelog/2017_11_06/o1_mf_1_1950_f014z3z6_.arc thread=1 sequence=1950 List of Archived Log Copies for database with db_unique_name MOTDC2 ===================================================================== Key Thrd Seq S Low Time ------- ---- ------- - --------- 1300755 1 1945 A 06-NOV-17 Name: /orafra/db/MOTDC2/archivelog/2017_11_06/o1_mf_1_1945_f014l36l_.arc deleted archived log archived log file name=/orafra/db/MOTDC2/archivelog/2017_11_06/o1_mf_1_1945_f014l36l_.arc RECID=4422 STAMP=959363283 Deleted 1 objects
The files are still protected against a delete. As we can see the statement triggers a RMAN-08120 warning, because the transactions are not yet applied on the standby.
When restoring the redo apply on the standby, the delete from RMAN is also working again.
Other Setups
In this example we used a Maximum Performance protection mode in Data Guard. Our goal was to apply all transactions on the standby as soon as possible, but with a minimal impact on the primary database.
Data Guard can also be used in various other configurations. You can configure an “apply delay”, which can protect you for user errors on the standby database. Another configuration is the Snapshot Standby database, where you temporarily stop the redo apply on the standby, and open the database for testing purposes.
In both these cases your policy could check if the transactions are shipped to, but not applied on the standby database:
RMAN> CONFIGURE ARCHIVELOG DELETION POLICY TO SHIPPED TO ALL STANDBY ;
Conclusion
The “CONFIGURE ARCHIVELOG DELETION POLICY TO APPLIED ON ALL STANDBY;” setting in RMAN is a good protection for the archive log files in a Data Guard environment where the standby is used for disaster recovery. It protects the files from being deleted before all the transactions are applied on the standby.
This setting also configures an automatic cleanup of the archive log files from the FRA. But files might only be removed after a confusing ORA-19815 warning.
A better solution is not to wait for the automatic cleanup, but to delete the files as part of the backup procedure.
If, for some reason, the transactions are not applied on the standby, the delete command triggers a RMAN-08120 warning, and the archived log files are not deleted. And if the FRA is filling up with a ORA-19815 warning, the automatic cleanup will still remove all files that are eligible for deletion.
Documentation: https://docs.oracle.com/database/122/RCMRF/CONFIGURE.htm#GUID-B5094E73-C26C-4FED-AE39-8C2E9540050A__CHDIFEEE
Thanks for your Quality information the product developed by the company is perfect.Thanks for giving such a wonderful blog. https://www.erptree.com/course/oracle-r12-financials-training-in-ameerpet-hyderabad/
Thanks Bastiaan! This blog helped me.
Thanks for informative article
I wonder if behavior is same when using shipped option like below
CONFIGURE ARCHIVELOG DELETION POLICY TO SHIPPED TO ALL STANDBY;
Thank you. The "shipped" option can be used in situations where we do not apply the redo on the standby database immediately.
2 situations when the redo is shipped to the standby, but not applied are :
- DELAY=minutes attribute of the LOG_ARCHIVE_DEST_n initialization parameter
- when you convert the standby database to a snapshot standby
So, then you can choose to create a policy that deletes the archives from the primary when they are shipped to the standby , but not yet applied. The rest of the behavior should be the same indeed.
Very useful information ..Great
Does FRA retention target db_flashback_retention_target plays part in this delayed removal ?
What if we want to set threshold for archive logs deletion(which are already applied on standby DB) ? is there any way we can do that ?
Thank you so much for sharing this well written article with all - very objectively presented indeed!
God Bless!
Thank You so much for such a detailed and simple explanation with examples.