Introduction
In an Oracle Data Guard environment, sometimes the standby database falls far behind the primary or archive logs are missing. In such cases, normal recovery fails and rebuilding the standby from scratch is time-consuming.
A faster and safer approach is to resynchronize the standby database using an RMAN incremental backup taken from the primary database starting at the standbyβs SCN.
This blog explains the step-by-step procedure to resync a physical standby database using RMAN incremental backup.
When Do We Use This Method?
- Missing archive logs on standby
- Standby lag is very high
- ORA- errors during managed recovery
- Network or disk issues caused gap
- Want to avoid full standby rebuild
Step 1: Check the Standby Database SCN
Connect to the standby database and identify the lowest SCN.
SELECT CURRENT_SCN FROM V$DATABASE;SELECT MIN(fhscn) FROM X$KCVFH;SELECT MIN(kc.fhscn)FROM X$KCVFH kc, V$DATAFILE ddWHERE kc.hxfil = dd.file#AND dd.enabled != 'READ ONLY';
π Why this is important
RMAN incremental backup must start from the lowest SCN of standby, otherwise recovery will fail.
Step 2: Stop Managed Recovery and Shutdown Standby
On the standby database:
ALTER DATABASE RECOVER MANAGED STANDBY DATABASE CANCEL;SHUTDOWN IMMEDIATE;
π This ensures datafiles are consistent before applying incremental backup.
Step 3: Take Incremental Backup on Primary
Connect to the primary database using RMAN:
BACKUP INCREMENTAL FROM SCN <LOWEST_SCN>DATABASEFORMAT '/oracle/backup/increment_%U.bkp'DEVICE TYPE DISK;
π This backup contains only the changed blocks since the standby SCN.
Step 4: Transfer Backup to Standby Server
Copy the RMAN backup to the standby host:
scp /oracle/backup/increment_*.bkp oracle@standby:/oracle/backup/
Step 5: Create Standby Control File on Primary
On the primary database:
ALTER DATABASE CREATE STANDBY CONTROLFILE AS '/oracle/backup/standby.ctl';
Copy it to the standby server:
scp /oracle/backup/standby.ctl oracle@standby:/oracle/backup/
Step 6: Start Standby Database in NOMOUNT
On the standby database:
STARTUP NOMOUNT;
Step 7: Restore Standby Control File
Using RMAN on standby:
RESTORE STANDBY CONTROLFILE FROM '/oracle/backup/standby.ctl';
Step 8: Mount the Standby Database
ALTER DATABASE MOUNT STANDBY DATABASE;
Step 9: Catalog the Incremental Backup
Tell RMAN where the backup files are located:
CATALOG START WITH '/oracle/backup/';
Step 10: If Datafile Locations Differ (Important)
If primary and standby datafile paths are different, run:
CATALOG START WITH '/new_datafile_location/';SWITCH DATABASE TO COPY;
π This maps datafiles correctly on the standby
Step 11: Recover the Standby Database
Apply the incremental backup:
RECOVER DATABASE NOREDO;
π NOREDO is used because redo will be applied later via MRP.
Step 12: Start Managed Recovery (MRP)
Finally, start redo apply:
ALTER DATABASE RECOVER MANAGED STANDBY DATABASEUSING CURRENT LOGFILEDISCONNECT FROM SESSION;
Verification
Check recovery status:
SELECT PROCESS, STATUS, THREAD#, SEQUENCE#FROM V$MANAGED_STANDBY;
Check archive gap:
SELECT * FROM V$ARCHIVE_GAP;