SWITCHOVER

The SWITCHOVER function can be used to perform a database switchover.

SWITCHOVER Function

DBMS_DG.SWITCHOVER (
     db_name              IN VARCHAR2,
     severity             OUT BINARY_INTEGER)
RETURN BINARY_INTEGER;

Parameters

Parameter Description
db_name The DB_UNIQUE_NAME initialization parameter value of the standby database to switch over to.
severity The severity associated with the status returned by this function. Severity will be one of the following Oracle error numbers:
  • ORA-0: normal, successful completion
  • ORA-16501: The Oracle Data Guard broker operation failed.
  • ORA-16502: The Oracle Data Guard broker operation succeeded with warnings.

Usage Notes

  • This function returns a binary integer.

  • 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-ON state so redo transport services are started.
    • The standby database must be enabled and in the APPLY-ON state, 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. 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.
  • If an Oracle RAC primary database is becoming a physical standby database, all but one instance of the primary database will be shut down before performing the switchover. See Switchover for details.
  • You cannot 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.

Return Values

Error Description
ORA-00000: normal, successful completion

The switchover completed successfully.

ORA-16540: invalid argument The name specified for the database was not a valid DB_UNIQUE_NAME value.
ORA-16600: not connected to target standby database This function cannot be called when connected to the primary database. Call this function while connected to the target standby database.
ORA-16732: Oracle Clusterware is restarting the database instance Oracle Clusterware is restarting the database to the mode required by the broker. Once the database has been restarted, retry this function call.
ORA-16897: start database to mount mode The switchover was completed successfully and the client must restart the old primary database to the mount mode.
ORA-16897: start database to open mode The switchover was completed successfully and the client must restart the old primary database to the open mode.
Other

The Data Guard broker unable to complete the switchover and the return value will indicate the reason for this failure.