26 October 2015

Sync standby database using incremental backups

Hello friends, this article is about syncing the standby database with the primary database using the incremental backup method. There was an upgrade activity in the project where one of the DR location was blacked out for a switch upgrade or something. This created a huge gap in the archive shipping to the DR location, also, the archive logs were deleted at the primary location when the RMAN backups ran during the outage. The only other easy option left was to recover using the incremental backups from the primary database.

Cancel the MRP process at the standby database and get the minimum SCN using the below commands:

ALTER DATABASE RECOVER MANAGED STANDBY DATABASE CANCEL;

select to_char(current_scn) from v$database;

select min(fhscn) from x$kcvfh;

select min(f.fhscn) from x$kcvfh f, v$datafile d where f.hxfil =d.file# and d.enabled != 'READ ONLY';


TO_CHAR(CURRENT_SCN)
----------------------------------------
33750546754

SQL> SQL>
MIN(FHSCN)
----------------
33750545679

SQL> SQL>
MIN(F.FHSCN)
----------------
33750545679


go to the primary database and take an incremental backup using the minimum SCN you get from the above queries, in this case the SCN used was "33750545679"

run
{
allocate channel d0 type disk FORMAT '/dbsabbkp/rmanbkp/%d_%s_%t.bak';
allocate channel d1 type disk FORMAT '/dbsabbkp/rmanbkp/%d_%s_%t.bak';
allocate channel d2 type disk FORMAT '/dbsabbkp/rmanbkp/%d_%s_%t.bak';
allocate channel d3 type disk FORMAT '/dbsabbkp/rmanbkp/%d_%s_%t.bak';
backup as compressed backupset incremental from scn 33750545679 database;
copy current controlfile to '/dbsabbkp/rmanbkp/control01full_%d_%t_%U.bak';
backup current controlfile for standby format '/dbsabbkp/rmanbkp/standbycontrol_%d_%T_%U.ctl';
RELEASE CHANNEL d0;
RELEASE CHANNEL d1;
RELEASE CHANNEL d2;
RELEASE CHANNEL d3;
}


scp the backup files to the standby database.

scp oracle@10.1.1.7:/dbstpbkp/rmanbkp

At the standby database server

rman target /
startup nomount;

restore standby controlfile from '/dbsabbkp/rmanbkp/standbycontrolXXXXXX.ctl';

sql 'alter database mount standby database';

catalog start with '/dbsabbkp/rmanbkp';

RECOVER DATABASE NOREDO;

alter database recover managed standby database disconnect from session;


On Primary:-
==========

select thread#, max(sequence#) "Last Primary Seq Generated"
from v$archived_log
where first_time between (sysdate-1) and (sysdate+1)
group by thread# order by 1;

On Standby:-
==========

select thread#, max(sequence#) "Last Standby Seq Received"
from v$archived_log
group by thread# order by 1;

select thread#, max(sequence#) "Last Standby Seq Applied"
from v$archived_log where applied='YES'
group by thread# order by 1;

SELECT THREAD#, SEQUENCE#, APPLIED FROM V$ARCHIVED_LOG ORDER BY SEQUENCE# ASC;

select process, thread#, sequence#, status from v$managed_standby where process='MRP0';

1 comment: