This topic describes the preparations required for you to switch the roles of the primary and standby clusters. To be specific, it describes how to obtain the cluster information, how to select a switchover mode, and how to select a standby cluster to switch it to the primary role.
Obtain the cluster information
Query the V$OB_CLUSTER view to obtain the role, status, protection mode, and protection level of each cluster.
Procedure:
Log on to the
systenant as therootuser.Access the database named
oceanbase.obclient> USE oceanbase;Execute the following statement to obtain the role and status of the current cluster:
obclient> SELECT CLUSTER_ID, CLUSTER_NAME, CLUSTER_ROLE, CLUSTER_STATUS FROM V$OB_CLUSTER; +------------+--------------+--------------+----------------+ | CLUSTER_ID | CLUSTER_NAME | CLUSTER_ROLE | CLUSTER_STATUS | +------------+--------------+--------------+----------------+ | 1 | obcluster | PRIMARY | VALID | +------------+--------------+--------------+----------------+ 1 row in setParameters:
CLUSTER_IDindicates the ID of the current cluster. The primary and standby clusters have different cluster IDs.CLUSTER_NAMEindicates the name of the current cluster. The primary and standby clusters have the same cluster name.CLUSTER_ROLEindicates the role of the current cluster.PRIMARYindicates a primary cluster, andPHYSICAL STANDBYindicates a standby cluster.CLUSTER_STATUSindicates the status of the current cluster.VALIDindicates that the cluster is normal.DISABLEDindicates that synchronization is disabled. Only the primary and standby clusters in theVALIDstate support role switchover.
After you identify the primary cluster, you can query the
V$OB_STANDBY_STATUSview of the primary cluster to obtain the list of all standby clusters and their status.In this example, two standby clusters whose IDs are respectively
2and3are in theVALIDstate.obclient> SELECT CLUSTER_ID, CLUSTER_NAME, CLUSTER_ROLE, CLUSTER_STATUS FROM V$OB_STANDBY_STATUS; +------------+--------------+------------------+----------------+ | CLUSTER_ID | CLUSTER_NAME | CLUSTER_ROLE | CLUSTER_STATUS | +------------+--------------+------------------+----------------+ | 2 | obcluster | PHYSICAL STANDBY | VALID | | 3 | obcluster | PHYSICAL STANDBY | VALID | +------------+--------------+------------------+----------------+ 2 rows in setExecute the following statement to obtain the protection mode and protection level of the current cluster:
obclient> SELECT PROTECTION_MODE, PROTECTION_LEVEL FROM V$OB_CLUSTER; +--------------------+--------------------+ | PROTECTION_MODE | PROTECTION_LEVEL | +--------------------+--------------------+ | MAXIMUM PROTECTION | MAXIMUM PROTECTION | +--------------------+--------------------+ 1 row in setFor more information, see Protection modes and protection levels.
Select a switchover mode
Role switchover operations are divided into two types:
Switchover
When the primary cluster is available, you can switch the roles of the primary cluster and a standby cluster to ensure lossless switchover.
A switchover is performed in two stages: switching the primary cluster to the standby role and switching the standby cluster to the primary role.
Failover
A failover allows you to switch a standby cluster to the primary role when the primary cluster is unavailable. Failover operations are divided into lossless failover and lossy failover. For more information about how to select an appropriate failover statement, see Preparations for a failover.
Select a standby cluster to be switched to the primary role
When multiple standby clusters exist, select an appropriate one as the target cluster to be switched to the primary role. Consider the following points when you perform this operation:
The region of the standby cluster.
Determine the region of the new primary cluster and then select the standby cluster that is to be switched to the primary role based on the region.
The hardware configurations, including the CPUs and I/O bandwidth.
Ensure that the hardware configurations meet your business requirements.
The synchronization latency of the standby cluster.
When the standby cluster is in the MAXIMUM PERFORMANCE mode, a longer synchronization latency between the standby cluster and the primary cluster means a longer switch time and more data loss during a failover. We recommend that you select a standby cluster with a smaller synchronization latency.
The protection mode and protection level of the standby cluster.
In MAXIMUM PROTECTION or MAXIMUM AVAILABILITY mode, only a standby cluster in
SYNCmode can be switched to the primary role. During a failover, an appropriate failover statement must be selected based on the protection mode and the protection level.
To view information about clusters, perform the following steps:
Query the
CURRENT_SCNfield in theV$OB_CLUSTERview of each cluster to obtain the synchronization progress of the cluster.CURRENT_SCNis a UNIX timestamp indicating the current synchronization progress. It is an integer value in microseconds.For example, you can log on to standby cluster 2 and execute the following SQL statement to query its synchronization progress:
obclient> SELECT CURRENT_SCN, USEC_TO_TIME(CURRENT_SCN) AS SYNC_TS FROM V$OB_CLUSTER; +------------------+----------------------------+ | CURRENT_SCN | SYNC_TS | +------------------+----------------------------+ | 1596354672506590 | 2020-08-02 15:51:12.506590 | +------------------+----------------------------+ 1 row in setA greater value of
CURRENT_SCNindicates a lower synchronization latency of the standby cluster. A standby cluster with a low synchronization latency can be selected as the target standby cluster to be switched to the primary role. You can subtract the value ofCURRENT_SCNof the standby cluster from the value ofCURRENT_SCNof the primary cluster to obtain the synchronization latency of the standby cluster.Query the
V$OB_STANDBY_STATUSview of the primary cluster to view the configurations and protection level of each standby cluster.obclient> SELECT CLUSTER_ID, PROTECTION_LEVEL, REDO_TRANSPORT_OPTIONS FROM V$OB_STANDBY_STATUS; +------------+---------------------+------------------------------+ | CLUSTER_ID | PROTECTION_LEVEL | REDO_TRANSPORT_OPTIONS | +------------+---------------------+------------------------------+ | 2 | MAXIMUM PROTECTION | SYNC NET_TIMEOUT = 30000000 | | 3 | MAXIMUM PERFORMANCE | ASYNC NET_TIMEOUT = 30000000 | +------------+---------------------+------------------------------+ 2 rows in setParameters:
REDO_TRANSPORT_OPTIONSindicates the log transfer configurations of each standby cluster.SYNCindicates a standby cluster in SYNC mode.ASYNCindicates a standby cluster in ASYNC mode.PROTECTION_LEVELindicates the protection level of each standby cluster. It is equivalent to thePROTECTION_LEVELfield in theV$OB_CLUSTERview.
You can also view the primary/standby relationship and synchronization latency in OCP by performing the following steps:
Log on to the OCP console as the administrator.
The Clusters page automatically appears.
In the Clusters section, view information about the primary cluster and click the Plus icon on the left of the primary cluster to view information about the corresponding standby clusters.
Click the name of the primary cluster to go to the primary cluster details page. In the left-side navigation pane, click Topology.
The topology shows the role of each cluster. You can also view the synchronization latency of each standby cluster.
For example, the synchronization latency of standby cluster 47 in the figure is 0.16s.
