Switchover of Databases (Primary To Standby and Standby To Primary)
Switchover of Databases (Primary To Standby and Standby To Primary)
Setup:
Pre-Switchover Checks:
These checks will have to be performed before the switchover activity is performed.
Use the following query to check if the managed recovery process is running on the standby
database.
The above fig. shows that the Managed Recovery Process (MRP0) is running on the standby
database. If MRP is not running, then start the process with real time enabled using the below query
in the standby database.
Once when the MRP has started on the standby database, make sure that the archive logs generated
at the primary end are shipped and getting applied to the standby database.
At the primary side check the maximum archive log sequence that has got generated:
At the standby side, check the maximum archive log sequence that has been applied from the
primary database:
In the above case, sequence# 82 is the maximum sequence generated at the primary database and
the same has been applied to the standby database.
For each temporary tablespace on the standby, verify that temporary files associated with that
tablespace on the primary database also exist on the standby database. Tempfiles added after initial
standby creation are not propagated to the standby. Run this query on both the primary and target
physical standby databases and verify that they match.
Verify that all datafiles are online on both primary and standby databases
Check whether all the datafiles are online prior to the switchover on both primary and standby
databases
On Primary side:
On Standby side:
If there are any offline datafiles, then bring them online using the below query
SQL>alter database datafile <datafile name> online;
Switchover Steps:
These steps are performed during the switchover process at the primary database side.
Check if there are any jobs running on the primary database using the below query.
SQL>select * from dba_jobs_running;
If there are any jobs running on the primary database and if it’s execution is not very important, then
terminate the job to continue further.
Block further job submission by setting the job_queue_processes parameter to 0 so that there would
be no jobs running during switchover.
In the above fig. the job_queue_processes parameter is set to 1000. Set this parameter to the value
0.
Verify that the primary database can be switched over to the standby
Query the switchover_status column of the v$database view on the primary database to determine
whether the primary database can be switched over to the standby.
A value of TO STANDBY or SESSIONS ACTIVE (which requires the WITH SESSION SHUTDOWN clause
on the switchover command) indicates that the primary database can be switched to the standby
role. If neither of these values is returned, a switchover is not possible because redo transport is
either mis-configured or is not functioning properly.
Once when value of switchover_status returns “TO STANDBY” or “SESSIONS ACTIVE” on the primary
database, then perform the switchover using the below query
Now the primary database is switched over to the standby database. The execution of the above
command may take some time and the archive logs generated during its execution would be
automatically applied to the standby database. Once when the command is executed with the
output as “Database altered”, it means that the primary database has been switched over to the
standby.
Note: Always perform the switchover of the primary database to standby database first and then switchover
the standby database to primary. If not, then you would end up landing with two primary databases
Query the switchover_status column from the v$database view at the standby side to determine
whether the standby database can be switched over to the primary database.
A value of TO PRIMARY or SESSIONS ACTIVE indicates that the standby database is ready to be
switched to the primary role. If neither of these values is returned, verify that redo apply is active
and that redo transport is configured and working properly. Continue to query this column until the
value returned is either TO PRIMARY or SESSIONS ACTIVE.
Once when the value of switchover_status returns “TO PRIMARY” or “SESSIONS ACTIVE” on the
standby database, then perform the switchover using the below query
Now the standby database has been switched over to the primary database.
The new primary database will be in mount state. Open this new primary database using the below
query.
Restart the new standby database (old primary database prim), bring it to the mount stage and start
the managed recovery process.
SQL>shutdown immediate;
SQL>startup mount;
Start the managed recovery process on the the new standby database (prim)
Post-Switchover tasks
Set the job queue processes to its original value on the new standby (prim).
Now the roles of the databases have been changed. The primary database (prim) has been changed
to standby database and the standby database (stnd) has been changed to primary database.
The archive logs that get generated in the new primary database (stnd) get shipped automatically to
the new standby database (prim) and they are applied on it automatically.
Maximum archivelog that has been shipped and applied to the new standby database (prim)
The roles can again be reversed by following the same above procedures.