Monday, September 2, 2019

Basic Steps to Create a Physical Standby Database in Oracle

Let see the basic steps to be followed to create a physical standby database.

Configuration of my servers -  

OS:                - Sun Solaris
Primary Hostname   - HYD-PROD-CBS-LIVE
Standby Hostname   - JPR-DR-CBS-LIVE
Database Version   - 11.2.0.4
Database Name (Primary and Standby): CBSLIVE
Database Unique Name (Primary):   CBS_PROD
Database Unique Name (Standby):   CBS_STDY 
Listener Port (Primary and Standby) -- We had multiple ports here but for example we are taking 1622
Primary Database Files Location   /data*/oradata/cbslive/
Standby Database Files Location   /data*/oradata/cbslive/

1) Create backup of spfile on production

create pfile='/tmp/initCBS_STDY.ora' from spfile;

2) Set following parameters on Production database.
alter system set log_archive_dest_2 = 'service=CBS_STDY';  #Net Service Name of Standby
alter system set log_archive_dest_state_2 = 'defer' ;
alter system set log_archive_config= 'dg_config=(CBS_PROD,CBS_STDY)'; #Add db_unique_name

3) Transfer the password file to $ORACL_HOME/dbs/ location
cd $ORACL_HOME/dbs/
scp orapwCBS_PROD oracle@JPR-DR-CBS-LIVE:$ORACL_HOME/dbs/orapwCBS_STDY

4) Now it's time to take backup. We have different ways to take backup. If we will get downtime and the size of database is small then,
I] Backup - 
a) Using Cold backup ( User Managed )
shutdown the Primary database -
copy all the datafiles to standby.
scp /data*/oradata/cbslive/* oracle@JPR-DR-CBS-LIVE:/data*/oradata/cbslive/*
startup the Primary database.

b) Using Hot Backup ( User Managed )
Put Primary database in Begin Backup mode -
alter database begin backup;
copy all the datafiles to standby.
scp /data*/oradata/cbslive/* oracle@JPR-DR-CBS-LIVE:/data*/oradata/cbslive/*
End the Begin Backup mode -
alter database end backup;

II] Create Standby controlfile on Primary database -
alter database create standby controlfile as '/tmp/control01.ctl';

5) Transfer file '/tmp/initCBS_STDY.ora' and '/tmp/control01.ctl' to Standby server.

6) On standby server - Create standby spfile.
export ORACLE_SID=CBS_STDY
sqlplus / as sysdba
startup nomount pfile='/tmp/initCBS_STDY.ora';
create spfile from pfile='/tmp/initCBS_STDY.ora';
shut immediate;
startup nomount;
exit

7) Enable DG config parameters on standby database - 
alter system set fal_server = 'CBS_STDY';
alter system set db_unique_name = 'CBS_STDY';
alter system set log_archive_config= 'dg_config=(CBS_PROD,CBS_STDY)';

8) Now restore control file
show parameter control file
Check the location and copy the files to that location. I had controlfiles multiplexed at following 3 location.
cp  /tmp/control01.ctl /data/control/cbslive/control01.ctl
cp  /tmp/control01.ctl /data02/control/cbslive/control02.ctl
cp  /tmp/control01.ctl /data03/control/cbslive/control03.ctl

9) Mount the standby database;
alter database mount;

10) Post checks and Config -
a) Crosscheck control file's datafile locations and Physical datafile location if all are present.
b) Create SRL post on standby database. ( Though we create it on primary as well since they might ask for switchover too )
  select * from v$standby_log;
c) Now enable the destination on production to enable log shipping to standby database
  alter system set log_archive_dest_state_2 = 'enable' scope=both;

11) Once everything is placed, Start the MRP
  alter database recover managed standby database disconnect from session;

How to create Physical standby in Oracle

Creating a Physical standby database in oracle requires certain pre-requite to be fulfilled. And creation will be based on scenario and environment you are in!

Pre-requistes -

1. Determine how much disk space will be required.
2. Create same mount points on DR as that of Primary databases.
3. Additional Backup space will be required on both side ie primary as well as standby.
4. Get port opening done between both the servers Primary and Standby database.(Contact with your Network team and Firewall team for more details)
5. Version of Oracle home and grid home installed on standby database should match with Primary database.
6. Primary database in force logging mode and archivelog mode.
7. Listener is configured and running on both servers - Primary and Standby.
8. The Platform/OS of the Standby Database server is the same as the Primary Site
9. We can have hetrogenous standby database depending upon the combination.



Basic Steps for creating a standby database - Click here


1. Backup the primary database including archives.
2. Making the backup available for the standby creation process.
3. Creating the Parameter file & directories if not available on the standby database server.
4. Prepare RMAN standby script.
5. Execute the RMAN script.
6. Additional steps to enable Data guard

Here are scenarios I came across and have tried it.

How To Create Physical Standby On Normal File System on New Host for ASM Primary
How To Create Physical Standby On ASM file system on New Host for ASM Primary
How To Creating Physical Standby Using RMAN DUPLICATE...FROM ACTIVE DATABASE
How To Create Physical Standby using 12c Feature