Oracle 12c DataGuard Switchover and Switchback
Please check my previous article on Active standby database.
How to build ACTIVE STANDBY DATABASE using RMAN DUPLICATE command in 12c.(Video included)
After configuring data guard, databases would be either primary and standby database role, and we can altered these roles without loss of data or without resetting logs. called switchover and switch back.
Switch-over :
Before performing switch over, kindly verify the state of data guard on both the instances by following SQL queries:
1 2 3 4 5 |
SYS>>ALTER SESSION SET nls_date_format='DD-MON-YYYY HH24:MI:SS'; SYS>>SELECT sequence#, first_time, next_time, applied FROM v$archived_log ORDER BY sequence#; 59 08-APR-19 08-APR-19 YES 60 08-APR-19 08-APR-19 YES 61 08-APR-19 08-APR-19 YES |
1 2 3 4 |
SYS>> select dest_name,status,error from v$archive_dest where dest_name='LOG_ARCHIVE_DEST_2'; DEST_NAME STATUS ERROR -------------------- ----------------------------------------------------------------- LOG_ARCHIVE_DEST_2 VALID |
1 |
SYS>>select message from v$dataguard_status; |
Note: This command will give you appropriate message about the data guard current status.
After getting confirmation on data guard smooth activity, we can instantiate switchover activity by issuing following sort of commands:
On Primary database:
Step 1 :
Connect to Primary database and convert primary database to standby.
1 2 3 |
[oracle@pr ~]$ sqlplus / as sysdba SQL> alter database commit to switchover to standby; Database altered. |
Step 2 :
Shutdown primary database:
1 |
SYS>> shutdown immediate; |
Step 3 :
Startup nomount old primary database as new standby database:
1 2 3 4 5 6 7 |
SYS>> startup nomount ORACLE instance started. Total System Global Area 972898304 bytes Fixed Size 2219272 bytes Variable Size 805307128 bytes Database Buffers 159383552 bytes Redo Buffers 5988352 bytes |
1 2 |
SQL>> alter database mount standby database; Database altered. |
1 2 |
SYS>> alter database recover managed standby database disconnect from session; Database altered. |
Verify database role on old primary database:
1 2 3 4 |
SYS>>select name,open_mode,database_role from v$database; NAME OPEN_MODE DATABASE_ROLE --------- -------------------- ---------------- prod MOUNTED PHYSICAL STANDBY |
On Standby database:
Step 4 :
On original standby database, Convert old standby database to primary database:
1 |
[oracle@dr ~]$ sqlplus / as sysdba |
Step 5 :
Convert old standby database as primary and shutdown database:
1 2 |
SYS>> alter database commit to switchover to primary; Database altered. |
1 2 3 4 |
SYS>> shutdown immediate; ORA-01109: database not open Database dismounted. ORACLE instance shut down. |
Step 6 :
Startup old standby database as primary database:
1 2 3 4 5 6 7 8 9 |
SYS>> startup ORACLE instance started. Total System Global Area 972898304 bytes Fixed Size 2219272 bytes Variable Size 717226744 bytes Database Buffers 247463936 bytes Redo Buffers 5988352 bytes Database mounted. Database opened. |
Verify database role on old standby database:
1 2 3 4 |
SYS>> select name,open_mode,database_role from v$database; NAME OPEN_MODE DATABASE_ROLE --------- -------------------- ---------------- RTS READ WRITE PRIMARY |
Switch over activity have completed successfully, our old primary database has become standby and old standby database has become primary database.
Note
To test above switchover activity, generate multiple archive logs on primary database and verify those archive logs being transferred on standby database.
Switchback:
To switchback, you have to follow same above mentioned 6 steps.
Just Try it.
Thanks