Monday, April 6, 2015

Database Switchover and Failover on DR

Switchover

Convert primary database to standby

Ensure that the last redo data transmitted from the primary database was applied on the standby database
SQL>select sequence#,applied from v$archived_log;
Check whether the primary is ready for switch.
SQL>select switchover_status from v$database;
If this query returns "TO STANDBY", then the environment is ready to switch. If it returns "SESSIONS ACTIVE", then the switch command should be used with the 'session shutdown' option.
SQL>connect / as sysdba;
SQL>alter database commit to switchover to physical standby with session shutdown;

Shutdown and mount primary database for standby database
SQL>shutdown immediate;
SQL>startup nomount;
SQL>alter database mount standby database;
SQL>ALTER DATABASE RECOVER MANAGED STANDBY DATABASE DISCONNECT FROM SESSION;
Verify the switchover status on new standby database
SQL>select switchover_status from v$database;
Above Query should return a value 'TO PRIMARY'

Check the Database role after switch
SQL>select database_role from v$database;
 
On the original standby database issue the following commands.

Convert standby database to primary

SQL>connect / as sysdba;
SQL>alter database commit to switchover to primary with session shutdown;

Shutdown and Startup old standby database as primary
SQL>SHUTDOWN IMMEDIATE;
SQL>STARTUP;

Check the Database role after switch
SQL>select database_role from v$database;

Failover

If the primary database is not available the standby database can be activated as a primary database using the following statements.

SQL>ALTER DATABASE RECOVER MANAGED STANDBY DATABASE FINISH;
SQL>ALTER DATABASE ACTIVATE STANDBY DATABASE;