Switchover and Failover are activities in which the standby database takes over the production database. It also describes how the database roles are reverted once the problem is fixed.
This role transition activity is of two types
- Switchover
- Failover
Switchover
Switchover is the act of changing the standby database into the primary database in a controlled manner. This is a planned activity and is safe from a data loss because the primary must complete all redo generation on the production data before allowing the switchover to commence. Switchback is nothing but a switchover in reverse order. This planned activity is usually done in a quiet period. The reason for the switchover may be a DR testing, patching activity, hardware change etc.
Once the switchover is complete, the redo from the new primary will be sent to the remaining standby servers, including the old primary. If you are using grid control or dataguard broker, the steps involved in a switchover process will be done automatically. But if you are doing it through SQLPLUS in a regular dataguard setup there will be some manual steps involved.
The actual command for the switchover is as follows
ALTER DATABASE COMMIT TO SWITCHOVER TO STANDBY;
When the switchover command is executed redo generation is stopped, all DML related cursors are invalidated and users are prevented from executing transactions or terminated and the current redo log is archived. A special switchover marker called the EOR (end of reader) in then placed in the header of the next sequence and the online redo logs are archived for the second time, sending the final sequences to the standby databases. At this point the physical standby database is closed and the final log switch is done without allowing the primary database to advance the sequence numbers. ALTER DATABASE COMMIT TO SWITCHOVER TO PRIMARY;
The physical primary switchover will wait for the MRP process to exit after processing the EOR redo and then convert the standby control file into a normal production control file. The final thing to do is to open the database for general production use.alter database open;
A logical standby also has to wait for the EOR redo from the primary to be applied and dataSQL apply to shut down before the switchover. Once the EOR has been processed, the GUAURD can be turned off and be open for production processing. Failover
ALTER DATABASE COMMIT TO SWITCHOVER TO PRIMARY;
Once the switchover is completed the protection mode will be maximum performance regardless of what is was before. To get it back to the original protection mode, you have to get the standby database up and running and run command to change to the appropriate protection mode.
Steps for a physical switchover
- Make sure all the dataguard parameters have been configured.
- Make sure the SRL files have been configured.
- Make sure you have a temporary datafile defined.
- Make sure flashback has been enabled.
select db_unique_name, protection_mode, synchronization_status, synchronized from v$archive_dest_status;
select client_process, process, sequence#, status from v$managed_standby;
Check the log sequence# on the primary also.
select thread#, sequence#, status from v$log;
select client_process, process, sequence#, status from v$managed_standby;
select process, operation, r.status, mbytes_processed pct, s.status from v$rman_status r, v$session s where r.sid=s.sid;
Once the checks have been carried out, you are ready to perform the switchover.alter system set log_archive_trace=8129;
To switch off the logging level
alter system set log_archive_trace=0;
If you are using flashback, make sure to drop the GRP restore point on all the databases after the switchover is complete, otherwise you will be generating permanent flashback database logs forever.
select switchover_status from v$database;
Now we are ready to switchover. On the primary database orcl.alter database commit to switchover to physical standby with session shutdown;
Keep an eye on your alert logs, then check that first part of the switchover has completed
select switchover_status from v$database;
To finish off the switchover. On the physical standby database alpha.alter database commit to switchover to primary with session shutdown;
After this command the database will be in mount stat. Open the new primary database
alter database open;
Finish off the old primary and start it up as a standby
shutdown immediate;
startup mount;
alter database recover managed standby database using current logfile disconnect from session;
Performing a Failover to physical standby with SQLPlus
select name, value, time_computed from v$dataguard_stats where name like '%lag%';
Query to get the SCN
select thread#, sequence#, last_change#, last_time from v$standby_log;
Once you have chosen the target we are ready to failover.alter database recover managed standby database cancel;
alter database recover managed standby database finish;
Now issue the switchover command and open the database.
alter database commit to switchover to primary with session shutdown;
alter database open;
You can raise the protection mode if required.
set standby database to maximum protection;
alter database activate logical standby database finish apply;
select to_char(standby_became_primary_scn) failover_scn from v$database;
FAILOVER_SCN startup mount;
flashback database to SCN 10345610;
alter database convert to physical standby;
shutdown immediate;
startup mount;
The old primary will start to resolve any gap issues at the next log switch, which means we can start the MRP process to get this standby going to catchup as fast as possible
alter database recover managed standby database using current logfile disconnect from session;
Eventually the missing redos will be sent to the standby and applied, bring us back to synchronization again.
Finally shutdown and startup the new standby database and start the MRP process so that the redo logs will start applying at runtime.
shutdown immediate;
startup mount;
alter database recover managed standby database using current logfile disconnect from session;
No comments:
Post a Comment