This topic describes how to switch the roles of the primary cluster and a standby cluster by using commands.
Switch the primary cluster to the standby role
Verify that the primary cluster can be switched to the standby role.
Query the
SWITCHOVER_STATUSandSWITCHOVER_INFOfields in theV$OB_CLUSTERview of the primary cluster.Example:
obclient> SELECT SWITCHOVER_STATUS, SWITCHOVER_INFO FROM V$OB_CLUSTER; +-------------------+------------------------------+ | SWITCHOVER_STATUS | SWITCHOVER_INFO | +-------------------+------------------------------+ | TO STANDBY | SYNCED STANDBY CLUSTERS: 2,3 | +-------------------+------------------------------+ 1 row in setIn the example:
SWITCHOVER_STATUSindicates the current switchover status.TO STANDBYindicates that the primary cluster can be switched to the standby role.NOT ALLOWEDor another value indicates that the switchover condition is not met.When SWITCHOVER_STATUS is
TO STANDBY,SWITCHOVER_INFOindicates the candidate standby clusters that can be switched to the primary role. For example,SYNCED STANDBY CLUSTERS: 2,3indicates that the standby clusters whose cluster IDs (CLUSTER_ID) are respectively2and3can be switched to the primary role.When SWITCHOVER_STATUS is
NOT ALLOWED,SWITCHOVER_INFOindicates the reason why switchover is not allowed. For example,CHECK PRIMARY CLUSTER SERVER STATUSindicates that the server status of the primary cluster must be checked. OceanBase Database requires that all servers be active during switchover. If some servers are inactive, switchover is not allowed.For information about troubleshooting methods corresponding to the values of the
SWITCHOVER_INFOfield, see Switchover errors.
Run the following command on the primary cluster to switch its role to
PHYSICAL STANDBY:obclient> ALTER SYSTEM COMMIT TO SWITCHOVER TO PHYSICAL STANDBY; Query OK, 0 rows affectedAfter the command is executed, the primary cluster is switched to the standby role, and
SWITCHOVER_STATUSchanges toSWTICHOVER SWITCHING.obclient> SELECT CLUSTER_ID, CLUSTER_ROLE, SWITCHOVER_STATUS FROM V$OB_CLUSTER; +------------+------------------+----------------------+ | CLUSTER_ID | CLUSTER_ROLE | SWITCHOVER_STATUS | +------------+------------------+----------------------+ | 1 | PHYSICAL STANDBY | SWITCHOVER SWITCHING | +------------+------------------+----------------------+ 1 row in set
Switch a standby cluster to the primary role
In the target standby cluster, run the following command to verify that it can be switched to the primary role:
obclient> SELECT SWITCHOVER_STATUS, SWITCHOVER_INFO FROM V$OB_CLUSTER; +-------------------+-----------------+ | SWITCHOVER_STATUS | SWITCHOVER_INFO | +-------------------+-----------------+ | TO PRIMARY | | +-------------------+-----------------+ 1 row in setWhen
SWITCHOVER_STATUSisTO PRIMARY, the standby cluster can be switched to the primary role. When SWITCHOVER_STATUS isNOT ALLOWED, the standby cluster cannot be switched to the primary role, andSWITCHOVER_INFOindicates the reason.If no standby cluster can be switched to the primary role, you can run the following command on the original primary cluster to switch it back to the primary role:
obclient> ALTER SYSTEM COMMIT TO SWITCHOVER TO PRIMARY; Query OK, 0 rows affectedRun the following command on the target standby cluster to switch it to the primary role:
obclient> ALTER SYSTEM COMMIT TO SWITCHOVER TO PRIMARY; Query OK, 0 rows affectedAfter the command is executed, the standby cluster is switched to the primary role. You can run the following command to query the
V$OB_CLUSTERview to verify the switching result:obclient> SELECT CLUSTER_ID, CLUSTER_ROLE, SWITCHOVER_STATUS, SWITCHOVER_INFO FROM V$OB_CLUSTER; +------------+--------------+-------------------+------------------------------+ | CLUSTER_ID | CLUSTER_ROLE | SWITCHOVER_STATUS | SWITCHOVER_INFO | +------------+--------------+-------------------+------------------------------+ | 2 | PRIMARY | TO STANDBY | SYNCED STANDBY CLUSTERS: 1,3 | +------------+--------------+-------------------+------------------------------+ 1 row in set