Recover Standby Database By Using RMAN Incremental Backup

By using RMAN incremental backups to synchronize a physical standby database, it is fast and easy without installing datafiles or history archive logs required.

This post demonstrates how to recover standby database with a big gap behind primary database in 11g.

Stop the managed recovery process (MRP)

SQL> ALTER DATABASE RECOVER MANAGED STANDBY DATABASE CANCEL;

On standby database, get the lowest SCN

SQL> SELECT CURRENT_SCN FROM V$DATABASE;

CURRENT_SCN
-----------
7.8880E+12

SQL> set numwidth 16
SQL> /

CURRENT_SCN
----------------
7888036454134

SQL> select min(fhscn) from x$kcvfh;

MIN(FHSCN)
----------------
7883734410408

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

MIN(F.FHSCN)
----------------
7883734410408

SQL> select CHECKPOINT_CHANGE# from v$datafile_header;

MIN(CHECKPOINT_CHANGE#)
-----------------------
7883734410408

On primary database, RMAN backup from SCN of previous step

Take a SCN backup, and copy backup onto standby server.

RMAN> BACKUP INCREMENTAL FROM SCN 7883734410408 DATABASE 
      FORMAT '/tmp/testdb_styby_%U' tag 'INCFORSTANDBY';

Prepare Standby ControlFile and New Datafiles

a) Create a standby control file from primary, and then copy onto standby database server. Replace the standby control file by using this newly created one.

-- From primary
--
SQL>ALTER DATABASE CREATE STANDBY CONTROLFILE AS '/tmp/TESTDBSTY.ctl';

-- From Standby
--
RMAN> SHUTDOWN IMMEDIATE ;
RMAN> STARTUP NOMOUNT; 
RMAN> RESTORE STANDBY CONTROLFILE FROM '/tmp/TESTDBSTY.ctl';

b) For new datafiles which are in Primary but not in standby database, copy them from primary to standby database server. Then catalog current all standby database datafiles, since the control file has been replaced by primary one.

RMAN> CATALOG START WITH '+DG1/tetsdbsty/datafile/'; 

c) Switch database to copy from RMAN.

RMAN> SWITCH DATABASE TO COPY;

Recover Standby Database

Catalog incremental backup, then recover standby database by using RMAN incremental backup of primary database.

RMAN> CATALOG START WITH '/tmp/testdb_styby';

RMAN> RECOVER DATABASE NOREDO;

Start the MRP process of standby database.

SQL>ALTER DATABASE RECOVER MANAGED STANDBY DATABASE USING CURRENT LOGFILE
     DISCONNECT FROM SESSION;

Check DataGuard Health

There is no gap between primary database and standby database now.

DGMGRL> show configuration;
Configuration - dg_oemrep
Protection Mode: MaxPerformance
Databases:
oemrep -    Primary database
stboemrep - Physical standby database

Fast-Start Failover: Disabled

Configuration Status:
SUCCESS
DGMGRL> show database "stboemrep";

Database - stboemrep

Enterprise Manager Name: OEMREP

Role:                    PHYSICAL STANDBY
Intended State:          APPLY-ON
Transport Lag:           0 seconds (computed 1 second ago)
Apply Lag:               0 seconds (computed 1 second ago)
Apply Rate:              4.93 MByte/s
Real Time Query:         OFF
Instance(s):
STBOEMREP

Database Status:
SUCCESS

DGMGRL>

How to Relocate Standby Database ASM Datafiles

The alternative for relocating ASM datafiles by RMAN commands :
CATALOG START WITH “+DATA2/../”
SWITCH DATABASE TO COPY.

TASK

This task is to relocate all the datafiles of diskgroup DATA1 to another diskgroup DATA2 for a standby database.

SOULUTION

1)Check the diskgroup space availability.

SQL> set pagesize 120
SQL> set linesize 180
SQL> select NAME,TOTAL_MB/1024,FREE_MB/1024,USABLE_FILE_MB/1024 
       from v$asm_diskgroup;

NAME T    TOTAL_MB/1024 FREE_MB/1024 USABLE_FILE_MB/1024
--------- ------------- ------------ -------------------
DATA1     1024.00977      15.6894531   15.6894531
OCR_VOTE    19.9931641    15.4257813   15.4257813
FRA        500.069336    210.331055   210.331055
DATA2     4000.55469    1816.02344   1816.02344

2)Leave managed standby database recovery still going. Create a RMAN script by using below query:

SQL> select 'backup as copy datafile '||file#||' format ''+DATA2'';' 
       from v$datafile 
      where name like '+DATA1%' order by 1;

'BACKUPASCOPYDATAFILE'||FILE#||'FORMAT''+DATA2'';'
---------------------------------------------------
backup as copy datafile 124 format '+DATA2';
backup as copy datafile 125 format '+DATA2';
backup as copy datafile 126 format '+DATA2';
backup as copy datafile 127 format '+DATA2';
.....
....
...
..
.

The final RMAN script content:

$cat move_DATA1_to_DATA2.rman

run {
allocate channel stdbych1 type disk;
allocate channel stdbych2 type disk;
allocate channel stdbych3 type disk;
allocate channel stdbych4 type disk;
backup as copy datafile 124 format '+DATA2';
backup as copy datafile 125 format '+DATA2';
backup as copy datafile 126 format '+DATA2';
backup as copy datafile 127 format '+DATA2';
....
...
..
.
}

3) Run the RMAN script to make a copy of all datafiles on diskgroup DATA1 onto diskgroup DATA2.

$nohup rman target / cmdfile=/u01/app/oracle/admin/scripts/move_DATA1_to_DATA2.rman  log=/u01/app/oracle/admin/scripts/move_DATA1_To_DATA2.log &

4) Stop the managed standby database recovery.

SQL> alter database recover managed standby database cancel;

Database altered.

5) Switch the datafiles.

RMAN>switch datafile 124 to copy;
RMAN>switch datafile 125 to copy;
RMAN>switch datafile 126 to copy;
RMAN>switch datafile 127 to copy;
....
...
..
.

6) Start the recovery.

SQL> alter database recover managed standby database using current logfile disconnect from session;

Database altered.

5) Archive log switch, check applied from alert.log, etc.

SQL>alter system archive log current ;
System altered.

6) Unmount diskgroup DATA1 on all the nodes, except the current node.

SQL> alter diskgroup data1 dismount;
Diskgroup altered.

7) Drop the diskgroup DATA1.

SQL> drop diskgroup data1;
drop diskgroup data1
*
ERROR at line 1:
ORA-15039: diskgroup not dropped
ORA-15053: diskgroup "DATA1" contains existing files

SQL> drop diskgroup data1 including contents;
Diskgroup dropped.

8) Scan disks and confirm the ASM Disks of DATA1 have been removed from ASM disks.

$su - 

# oracleasm listdisks
ASM_DISK01
ASM_DISK02
ASM_DISK03
ASM_DISK04
ASM_DISK05
ASM_DISK06
ASM_DISK07
ASM_DISK08
ASM_FRA01
ASM_SSD1  <----- DATA1 diskgroup
OCR_VOTE01

# oracleasm scandisks
Reloading disk partitions: done
Cleaning any stale ASM disks...
Cleaning disk "ASM_SSD1"
Scanning system for ASM disks...

# oracleasm listdisks
ASM_DISK01
ASM_DISK02
ASM_DISK03
ASM_DISK04
ASM_DISK05
ASM_DISK06
ASM_DISK07
ASM_DISK08
ASM_FRA01
OCR_VOTE01