This topic describes how to switch the roles of the primary cluster and a standby cluster in a command-line tool.
You must first switch the primary cluster to the standby role and then switch the standby cluster to the primary role.
Preparations for a switchover
Before you perform a switchover, obtain the cluster information and select an appropriate standby cluster.
For more information, see Preparations for a switchover.
Switch the primary cluster to the standby role
Notice
Before you verify whether the primary cluster can be switched to the standby role, perform the following query operations on your OceanBase database.
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 setNote:
The value of the
SWITCHOVER_STATUSfield indicates 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 the value of the SWITCHOVER_STATUS field is
TO STANDBY, the value of theSWITCHOVER_INFOfield indicates the IDs of 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 are2and3can be switched to the primary role.When the value of the SWITCHOVER_STATUS field is
NOT ALLOWED, the value of theSWITCHOVER_INFOfield indicates the reason why the switchover is not allowed. For example,CHECK PRIMARY CLUSTER SERVER STATUSindicates that the OBServer status of the primary cluster must be checked. To perform a primary/standby switchover, all OBServer nodes in the primary and standby OceanBase clusters must be active.For more information about the troubleshooting methods corresponding to the values of the
SWITCHOVER_INFOfield, see Switchover errors.
Execute the following statement on the primary cluster to switch its role to
PHYSICAL STANDBY:obclient> ALTER SYSTEM COMMIT TO SWITCHOVER TO PHYSICAL STANDBY; Query OK, 0 rows affectedThe primary cluster is switched to the standby role, and the value of the
SWITCHOVER_STATUSfield changes toSWITCHOVER 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, execute the following statement 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 the value of the
SWITCHOVER_STATUSfield isTO PRIMARY, the standby cluster can be switched to the primary role. When the value of the SWITCHOVER_STATUS field isNOT ALLOWED, the standby cluster cannot be switched to the primary role. The value of theSWITCHOVER_INFOfield indicates the reason.If no standby cluster can be switched to the primary role, you can execute the following statement 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 affectedExecute the following statement on the target standby cluster to switch it to the primary role:
obclient> ALTER SYSTEM COMMIT TO SWITCHOVER TO PRIMARY; Query OK, 0 rows affectedThe standby cluster is switched to the primary role. You can execute the following statement to query the
V$OB_CLUSTERview and 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