Thursday, June 26, 2014

Oracle Dataguard failover and reinstate primary

My scenario is we need to do some changes on database and in case of any issues want our dataguard instance to reinstate primary.

Steps to accomplish this work are:
  1. Turn off the Transport
  2. Do a log switch on primary to make sure that none of the current changes are going to DR
  3. Connect to standby database using dgmgrl from standby node and Failover to DR
  4. Shutdown primary database
  5. Startup primary database in mount mode
  6. Reinstate primary database
  7. Switch over to primary database;
Turn off the Transport
DGMGRL> show database 'RAC'
Database - RAC
  Role:            PRIMARY
  Intended State:  TRANSPORT-ON
  Instance(s):
    RAC1
    RAC2
Database Status:
SUCCESS
DGMGRL> edit database 'RAC' set state=TRANSPORT-OFF;
Succeeded.
DGMGRL> show database 'RAC'
Database - RAC
  Role:            PRIMARY
  Intended State:  TRANSPORT-OFF
  Instance(s):
    RAC1
    RAC2
Database Status:
SUCCESS
DGMGRL>
Do a log switch on primary to make sure that none of the current changes are going to DR
SQL> alter system switch logfile;
System altered.
SQL> alter system switch logfile;
System altered.
SQL>
Connect to standby database using dgmgrl from standby node and Failover to DR
DGMGRL> connect sys/*****@RAC_STBY
Connected.
DGMGRL> show configuration
Configuration - racdg
  Protection Mode: MaxPerformance
  Databases:
    RAC      - Primary database
    RAC_STBY - Physical standby database
Fast-Start Failover: DISABLED
Configuration Status:
SUCCESS
DGMGRL> failover to 'RAC_STBY'
Performing failover NOW, please wait...
Failover succeeded, new primary is "RAC_STBY"
DGMGRL> show configuration
Configuration - racdg
  Protection Mode: MaxPerformance
  Databases:
    RAC_STBY - Primary database
    RAC      - Physical standby database (disabled)
      ORA-16661: the standby database needs to be reinstated
Fast-Start Failover: DISABLED
Configuration Status:
SUCCESS
DGMGRL>
Shutdown primary database
[oracle@rac1 ~]$ srvctl stop database -d RAC
[oracle@rac1 ~]$
[oracle@rac1 ~]$ srvctl status database -d RAC
Instance RAC1 is not running on node rac1
Instance RAC2 is not running on node rac2
[oracle@rac1 ~]$
Startup primary database in mount mode
[oracle@rac1 ~]$ srvctl start database -d RAC -o mount
[oracle@rac1 ~]$
[oracle@rac1 ~]$ srvctl status database -d RAC
Instance RAC1 is running on node rac1
Instance RAC2 is running on node rac2
[oracle@rac1 ~]$
Reinstate primary database
DGMGRL> reinstate database 'RAC';
Reinstating database "RAC", please wait...
Operation requires shutdown of instance "RAC1" on database "RAC"
Shutting down instance "RAC1"...
ORA-01109: database not open
Database dismounted.
ORACLE instance shut down.
Operation requires startup of instance "RAC1" on database "RAC"
Starting instance "RAC1"...
ORACLE instance started.
Database mounted.
Continuing to reinstate database "RAC" ...
Reinstatement of database "RAC" succeeded
DGMGRL>
DGMGRL> show configuration
Configuration - racdg
  Protection Mode: MaxPerformance
  Databases:
    RAC_STBY - Primary database
    RAC      - Physical standby database
Fast-Start Failover: DISABLED
Configuration Status:
SUCCESS
DGMGRL> 
Switch over to primary database;
DGMGRL> switchover to 'RAC'
Performing switchover NOW, please wait...
New primary database "RAC" is opening...
Operation requires shutdown of instance "RAC_STBY1" on database "RAC_STBY"
Shutting down instance "RAC_STBY1"...
ORACLE instance shut down.
Operation requires startup of instance "RAC_STBY1" on database "RAC_STBY"
Starting instance "RAC_STBY1"...
ORACLE instance started.
Database mounted.
Database opened.
Switchover succeeded, new primary is "RAC"
DGMGRL>
DGMGRL> show configuration
Configuration - racdg
  Protection Mode: MaxPerformance
  Databases:
    RAC      - Primary database
    RAC_STBY - Physical standby database
Fast-Start Failover: DISABLED
Configuration Status:
SUCCESS
DGMGRL>
DGMGRL> show database 'RAC'
Database - RAC
  Role:            PRIMARY
  Intended State:  TRANSPORT-ON
  Instance(s):
    RAC1
    RAC2
Database Status:
SUCCESS
DGMGRL> 

No comments: