VirtualObjectives

Restoring a Physical Standby Database

This procedure covers the complete restore of a Physical Standby database.
We are assuming that the Physical Standby environment already exists and that you would like to refresh Standby with a recent copy of the Primary database.
The Primary database consists of a two node Oracle RAC.

In this example, we will be using two directories on the Standby server;
D:\RMAN_BACKUP\ will store the copy of the full backup files taken from your Production Oracle system.
D:\RMAN_BACKUP_OTHER\ will store other files like control files and log files, etc.
The reason is because the CATALOG process used later cannot handle files which are not part of a database backup set.
Make sure directories D:\RMAN_BACKUP\ and D:\RMAN_BACKUP_OTHER\ are empty and there is enough disk space to hold the backup files.

Restore Process

We are going to need a full backup of the Primary environment. This backup should also contain a Standby copy of the Control Files using the following RMAN script...

backup current controlfile for standby format 'N\somepath\%d_STANDBY_CTRL_%T_%s_%p';

Copy the backup files from your Primary environment into D:\RMAN_BACKUP\ on the Standby environment.
Move all non-backup files (control files, log files, etc.) from D:\RMAN_BACKUP\ to D:\RMAN_BACKUP_OTHER\

Connect to the database on Standby as the RMAN target.

Shut down the database:

Now remove all datafiles. We are assuming that these exist on the file system. Otherwise use ASMCMD to remove the datafiles from ASM.
In this example our datafiles exist in D: and E: under \oracle\oradata\db\
Delete all files under \oracle\oradata\db\ except except *.CTL

Startup database in nomount:

Restore the Standby control file.

Mount the database.

Catalog the backup files.

Type YES at the prompt.

On BOTH Primary nodes, disable the sending of archive logs to Standby.

Back on the Standby environment, we need to generate a script to rename datafiles to match where they will reside on the Standby environment.
Use Oracle SQL Developer to connect to Standby and run the the following script using [F9] key.
(Obviously, you will need to adapt the script to fit your requirements)

Select all results using [Ctrl] + [A] and copy.
Insert the results into a file called restore.rman

In the file restore.rman, insert the following at the top...

run {
allocate channel c1 device type disk;
allocate channel c2 device type disk;
allocate channel c3 device type disk;

... and at the end, append the following...

restore database force check readonly;
switch datafile all;
}

Save the file restore.rman.

Now we will begin the restore the database. This will take a long time.

Recovery Process

Next, clear all standby redo log groups (there may be more than 3)
Find size, total and names of redo log files on the standby database.

ALTER DATABASE CLEAR LOGFILE GROUP 1;
ALTER DATABASE CLEAR LOGFILE GROUP 2;
ALTER DATABASE CLEAR LOGFILE GROUP 3;
ALTER DATABASE CLEAR LOGFILE GROUP 4;
ALTER DATABASE CLEAR LOGFILE GROUP 5;
ALTER DATABASE CLEAR LOGFILE GROUP 6;
ALTER DATABASE CLEAR LOGFILE GROUP 7;
ALTER DATABASE CLEAR LOGFILE GROUP 8;
ALTER DATABASE CLEAR LOGFILE GROUP 9;
ALTER DATABASE CLEAR LOGFILE GROUP 10;
ALTER DATABASE CLEAR LOGFILE GROUP 11;
ALTER DATABASE CLEAR LOGFILE GROUP 12;
ALTER DATABASE CLEAR LOGFILE GROUP 13;
ALTER DATABASE CLEAR LOGFILE GROUP 14;
ALTER DATABASE CLEAR LOGFILE GROUP 15;
ALTER DATABASE CLEAR LOGFILE GROUP 16;
ALTER DATABASE CLEAR LOGFILE GROUP 17;
ALTER DATABASE CLEAR LOGFILE GROUP 18;
ALTER DATABASE CLEAR LOGFILE GROUP 19;
ALTER DATABASE CLEAR LOGFILE GROUP 20;

You need to add N+1 redo log groups.
There needs to be more redo logs on the Standby than there are on the Primary.
If there are 20 redo log groups on the Primary database (usually of 2 files each) then add group 21 on the Standby server.
Example below...

On the Standby database, start the managed recovery process (MRP):

Check the Oracle alert log file for errors.
Take any corrective action required to resolve any issues.

Bringing it Online

On BOTH Primary nodes, enable the sending of archive logs to Standby.

Check database role status...

Run the following script to check the gap...

Here is more information to determine if Data Guard is working and help diagnose and fix gaps in archivelogs.