Delete Archivelogs on Primary which were already applied to Standby with RMAN


Read our docs With Standard edition it's not possible to set RMAN Archivelog deletion policy on Primary to "Applied on Standby". 

Customers often want to prevent their RMAN backup scripts on primary database to delete archived logs which were not yet applied to Dbvisit Standby database.

This KB article describes possible way how to mimic this deletion policy using Dbvisit Standby components.

Problem Details

Problem Statement


Applicable Error Code


Affected Versions


Affected Platforms




In this workaround we will use dbvnet and dbvctl commands to obtain Standby Datbase recovery sequence and use this sequence number to perform archivelog deletion on primary database.

Step 1.  Create Sample RMAN deletion script:

vi delete_archlogs.rman

run {
delete archivelog until sequence &1;

Step 2: Create Sample Shell script to determine Standby Recovery Sequence



# Define Variables


# Get recovery SCN of standby DB

CMD_SCN="$DBVISIT_BASE/standby/dbvctl -f recovery_scn_time -d $DDC | head -1"

STB_SCN=`$DBVISIT_BASE/dbvnet/dbvnet -a $DESTINATION -p 7890 -e "$CMD_SCN"`

# Transform SCN to recovery Sequence

STB_SEQ=`$DBVISIT_BASE/standby/dbvctl -f scn_to_sequence -d $DDC -a scn=$STB_SCN | cut -d= -f3`

# substract 1 to get last applied sequence


# start RMAN backup script for deleting archlogs

rman target / @delete_archlogs.rman $STB_SEQ
Make sure to define variables according to your current environment. This shell script will then start sample RMAN script which will delete all archivelogs on primary which were not yet applied to Standby Database.
This is just an example - you will most likely have to integrate this into your existing backup scripts on the primary. The key variable is STB_SEQ which is last applied archivelog sequence on the standby database.
As always, be sure to test the scripts thoroughly before deploying them to production.
Sample Run together with log gap report for better understanding:
$ ./dbvctl -d DBVSIX -i

Dbvisit Standby log gap report for DBVSIX at 202004011959:
Description | SCN | Timestamp
Source 52800404 2020-04-01:19:59:05 +02:00
Destination 52800321 2020-04-01:19:57:50 +02:00

Standby database time lag (DAYS-HH:MI:SS): +00:01:15

Report for Thread 1
Current Sequence 90
Last Archived Sequence 89
Last Transferred Sequence 85
Last Transferred Timestamp 2020-04-01 19:58:44

Next Required Recovery Sequence 85

Transfer Log Gap 4
Apply Log Gap 5

$ ./

Recovery Manager: Release - Production on Wed Apr 1 19:59:18 2020

Copyright (c) 1982, 2018, Oracle and/or its affiliates. All rights reserved.

connected to target database: DBVSIX (DBID=574695139)

RMAN> run {
2> delete archivelog until sequence 84;
3> }
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=268 device type=DISK
deleted archived log
archived log file name=/u01/app/oracle/fast_recovery_area/DBVSIX/archivelog/2020_04_01/o1_mf_1_77_h89msbf1_.arc RECID=120 STAMP=1036610890
deleted archived log
archived log file name=/u01/app/oracle/fast_recovery_area/DBVSIX/archivelog/2020_04_01/o1_mf_1_78_h89mscdt_.arc RECID=121 STAMP=1036610891
deleted archived log
archived log file name=/u01/app/oracle/fast_recovery_area/DBVSIX/archivelog/2020_04_01/o1_mf_1_79_h89msdyq_.arc RECID=122 STAMP=1036610892
deleted archived log
archived log file name=/u01/app/oracle/fast_recovery_area/DBVSIX/archivelog/2020_04_01/o1_mf_1_80_h89msygt_.arc RECID=123 STAMP=1036610910
deleted archived log
archived log file name=/u01/app/oracle/fast_recovery_area/DBVSIX/archivelog/2020_04_01/o1_mf_1_81_h89mv3tv_.arc RECID=124 STAMP=1036610947
deleted archived log
archived log file name=/u01/app/oracle/fast_recovery_area/DBVSIX/archivelog/2020_04_01/o1_mf_1_82_h89ojwdr_.arc RECID=125 STAMP=1036612668
deleted archived log
archived log file name=/u01/app/oracle/fast_recovery_area/DBVSIX/archivelog/2020_04_01/o1_mf_1_83_h89ojx9z_.arc RECID=126 STAMP=1036612669
deleted archived log
archived log file name=/u01/app/oracle/fast_recovery_area/DBVSIX/archivelog/2020_04_01/o1_mf_1_84_h89ojz0p_.arc RECID=127 STAMP=1036612671
Deleted 8 objects

Recovery Manager complete.
Have more questions? Submit a request