SWITCHOVER
When you issue the SWITCHOVER command, the current primary
database becomes a standby database, and the specified standby database becomes the
primary database. This is known as a switchover operation.
Format
SWITCHOVER TO <db_unique_name> [WAIT [<timeout_in_seconds>]];
The WAIT option specifies that you want to wait for sessions to
drain before proceeding with the switchover. Use the
timeout_in_seconds option to specify the
wait time. The broker waits for the number of seconds specified, for
sessions to drain, and then proceeds with the switchover. Any
sessions that have not drained will be killed during the switchover
process.
If you include the WAIT option, but omit
timeout_in_seconds, the broker determines
the maximum drain_timeout value for all currently
active services, waits for up to that amount of time for all current
client requests to be processed, and then proceeds with the
switchover. The drain_timeout value is an option
that is specified on the SRVCTL utility's add
service or modify service
commands.
The value specified for timeout_in_seconds
overrides the value set using the drain_timeout
option.
The WAIT option is valid only when services
are configured with attributes related to Application Continuity in
Oracle Clusterware.
Note:
The WAIT option has been
deprecated in 26ai. Use the DrainTimeout
configuration property to specify a drain timeout for
switchover.
Command Parameters
- db_unique_name
-
The
DB_UNIQUE_NAMEinitialization parameter value of the standby database you want to change to the primary database role. - timeout_in_seconds
- The time allowed for resource draining to be completed, in seconds, before the
switchover operation proceeds.
Permitted values are 0 (zero) or any positive integer. The default value is an empty string indicating that this option is not set. If the value is zero, then draining occurs immediately and broker proceeds with the switchover. During the draining period, all current client requests are processed, but new requests are not accepted.
Usage Notes
-
If fast-start failover is enabled, you may switch over only to the fast-start failover target standby database.
-
The broker verifies that the primary and standby databases are in the following states before starting the switchover:
-
The primary database must be enabled and in the
TRANSPORT-ONstate so redo transport services are started. -
The standby database must be enabled and in the
APPLY-ONstate, with log apply services started.
-
-
The broker allows the switchover to proceed as long as there are no redo transport services errors for the standby database that you selected to participate in the switchover. However, errors occurring for any other bystander standby database will not prevent the switchover from proceeding.
-
Switchover to a logical standby database is not allowed when the configuration is operating in maximum protection mode.
-
If the broker configuration is operating in either maximum protection mode or maximum availability mode, the switchover maintains the protection mode even after the operation (described in Before You Perform a Switchover Operation). The switchover will not be allowed if the mode cannot be maintained because the target standby database of the switchover was the only standby that satisfied the protection mode requirement.
-
If the standby database that is assuming the primary role is a physical standby database, then the old primary database will be restarted after the switchover completes. Any client connections to the old primary are redirected to the physical standby database as shown in Example 10-14. If the standby database is a logical standby database, then neither the primary database nor the logical standby database is restarted.
-
If the standby database that is assuming the primary role is a physical standby database, then the original primary becomes a physical standby database.
-
If the standby database that is assuming the primary role is a logical standby database, then the original primary becomes a logical standby database.
-
It is not possible to switchover to a snapshot standby database.
-
If the standby database that is assuming the primary role is a logical standby database and there are physical standby databases in the configuration, after the switchover, the physical standby databases will be disabled.
Caution:
For this reason, Oracle generally recommends that you specify your physical standby database for switchover instead of your logical standby database. If you must switch over to your logical standby database, see Reenabling Disabled Databases After a Role Change to re-create your physical standby database.
If you intend to switch back to the original primary database relatively soon, you may allow the physical and snapshot standbys to remain disabled. Once you have completed the switchover back to the original primary, you may then reenable the physical and snapshot standby databases since they are still viable standbys for the original primary database.
-
If the database is managed by Oracle Clusterware, the broker does not open any PDBs on any of the instances. Instead, the broker notifies the Clusterware agent after the switchover completes, and the Clusterware agent opens PDBs on particular instances based on the service configuration.
Command Examples
Example 10-12 Successful Switchover From Primary to Physical Standby
This example shows a successful switchover in which the
physical standby database, South_Sales, transitions
into the primary role.
DGMGRL> SWITCHOVER TO 'South_Sales';
2021-03-08T18:46:18.576-05:00
Performing switchover NOW, please wait...
2021-03-08T18:46:31.899-05:00
New primary database "South_Sales" is opening...
2021-03-08T18:46:31.901-05:00
Operation requires start up of instance "north_sales1" on database "North_Sales"
Starting instance "north_sales1"...
Connected to an idle instance.
ORACLE instance started.
Connected to "north_sales1"
Database mounted.
Connected to "South_Sales"
2021-03-08T18:47:12.754-05:00
Switchover succeeded, new primary is "South_Sales"
2021-03-08T18:47:12.780-05:00
Switchover processing complete, broker ready.
Example 10-13 Unsuccessful Switchover Due to Use of O/S Authentication
If you connect to the database using operating system authentication, you can use any username and password to connect. However, DGMGRL may not be able to shut down and start up the primary and standby database automatically because it cannot remotely authenticate itself.
The following example shows a switchover that succeeded but returns an error because DGMGRL cannot shut down and start up the primary and standby databases.
DGMGRL> SWITCHOVER TO 'South_Sales';
Performing switchover NOW, please wait...
New primary database "South_Sales" is opening...
Operation requires shutdown of instance "north_sales1" on database "North_Sales"
Shutting down instance "north_sales1"...
ORA-01031: insufficient privileges
Warning: You are no longer connected to ORACLE.
Please complete the following steps to finish switchover:
shut down instance "north_sales1" of database "North_Sales"
start up and mount instance "north_sales1" of database "North_Sales"
Note:
For DGMGRL to restart instances automatically, you
must connect to the database using the same credentials
given in the last CONNECT command, even if
the last CONNECT command was used to
connect to another database.
You must manually issue the SHUTDOWN and
STARTUP commands to restart the new primary
and any standby instances that may have been shut down.
Example 10-14 Redirecting Client Connections to a Target Physical Standby Database
This example performs a successful switchover in which the
physical standby database South_Sales transitions
into the primary role. Connections to the old primary are
automatically reconnected to the new primary database,
South_Sales.
DGMGRL> SWITCHOVER TO South_Sales;
2021-03-08T18:42:38.906-05:00
Performing switchover NOW, please wait...
2021-03-08T18:42:39.704-05:00
Operation requires a connection to database "South_Sales"
Connecting ...
Connected to "South_Sales"
Connected as SYSDG.
2021-03-08T18:42:39.908-05:00
Continuing with the switchover...
2021-03-08T18:42:50.022-05:00
New primary database "South_Sales" is opening...
2021-03-08T18:42:50.023-05:00
Operation requires start up of instance "north_sales2" on database "North_Sales"
Starting instance "north_sales2"...
Connected to an idle instance.
ORACLE instance started.
Connected to "North_Sales"
Database mounted.
Connected to "South_Sales"
2021-03-08T18:43:31.457-05:00
Switchover succeeded, new primary is "South_Sales"
2021-03-08T18:43:31.486-05:00
Switchover processing complete, broker ready.
Example 10-15 Specifying a Zero Wait Time During Switchover
This example includes the WAIT option in the
SWITCHOVER command and sets the wait time
to zero seconds. Therefore, the broker does not wait for sessions to
drain and proceeds with the switchover operation.
DGMGRL> SWITCHOVER TO 'South_Sales' WAIT 0;
2021-03-08T18:29:17.674-05:00
WAIT 0 does not wait for sessions to drain; proceeding with switchover...
2021-03-08T18:29:27.995-05:00
New primary database "South_Sales" is opening...
2021-03-08T18:29:27.995-05:00
Oracle Clusterware is restarting database "North_Sales" ...
Connected to "South_Sales"
2021-03-08T18:30:09.375-05:00
Switchover succeeded, new primary is "South_Sales"
2021-03-08T18:30:09.421-05:00
Switchover processing complete, broker ready.
Example 10-16 Using the WAIT Clause to Specify a Wait Time During Switchover
This example includes the WAIT option in the
SWITCHOVER command and sets the wait time
to 23 seconds. Therefore, the broker waits for 23 seconds for
sessions to drain and then proceeds with the switchover.
DGMGRL> SWITCHOVER TO 'South_Sales' WAIT 23;
2021-03-08T18:26:29.412-05:00
Stopping services and waiting up to 23 seconds for sessions to drain...
2021-03-08T18:26:40.209-05:00
Done waiting for sessions to drain; proceeding with switchover now...
2021-03-08T18:26:54.411-05:00
New primary database "South_Sales" is opening...
2021-03-08T18:26:54.412-05:00
Oracle Clusterware is restarting database "North_Sales" ...
Connected to "South_Sales"
2021-03-08T18:27:39.045-05:00
Switchover succeeded, new primary is "South_Sales"
2021-03-08T18:27:39.084-05:00
Switchover processing complete, broker ready.