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;

No comments:

Post a Comment