Purpose
If the primary cluster is unavailable, you can use this statement to switch the standby cluster to the primary role. Failover operations are classified into lossless failover and lossy failover.
If the data in all partitions of the standby cluster is consistent, you can run a lossless failover statement to prevent data loss. You can also run a lossy failover statement to roll back the data in each partition until the data is consistent.
For more information about failover, see "Primary/Standby cluster management" in the OceanBase Database Administrator Guide.
Syntax
/* Lossless failover */
ALTER SYSTEM FAILOVER TO cluster_name CLUSTER_ID [=] cluster_id [FORCE];
/* Lossy failover */
ALTER SYSTEM ACTIVATE PHYSICAL STANDBY CLUSTER [FORCE];
Parameters
| Parameter | Description |
|---|---|
| cluster_name | The name of the standby cluster to perform a lossless failover. |
| cluster_id | The ID of the standby cluster to perform a lossless failover. |
| FORCE | For a lossless failover, skips the check of the protection mode and level of the standby cluster. For a lossy failover, forcibly performs it. For all failover operations, this keyword indicates that the check of other standby clusters in the DISABLED state is skipped. Failover is allowed even if any other standby cluster in the DISABLED state exists. |
Examples
Perform a lossless failover.
Ensure that the primary cluster is in the unavailable state.
Check the protection mode and level of each standby cluster to ensure that a lossless failover can be performed.
obclient> SELECT PROTECTION_MODE, PROTECTION_LEVEL FROM V$OB_CLUSTER; +--------------------+--------------------+ | PROTECTION_MODE | PROTECTION_LEVEL | +--------------------+--------------------+ | MAXIMUM PROTECTION | MAXIMUM PROTECTION | +--------------------+--------------------+Execute the following statement to switch the standby cluster to the primary role.
When a failover is performed, the cluster is in the maximum performance mode by default, and the original primary cluster and other standby clusters are in the
DISABLEDstatus.For more examples about how to switch the primary cluster to the standby role for access, see CONVERT.
obclient> ALTER SYSTEM FAILOVER TO 'obtest' CLUSTER_ID=2; obclient> SELECT CLUSTER_ID, CLUSTER_ROLE, CLUSTER_STATUS FROM V$OB_STANDBY_STATUS; +------------+------------------+----------------+ | CLUSTER_ID | CLUSTER_ROLE | CLUSTER_STATUS | +------------+------------------+----------------+ | 1 | PHYSICAL STANDBY | DISABLED | +------------+------------------+----------------+Optional. Manually initiate a major compaction.
After the lossless failover is completed, if the major compaction version of the clusters is
1, we recommend that you initiate a major compaction and add a new standby cluster after the major compaction is completed.obclient> ALTER SYSTEM MAJOR FREEZE;
Perform a lossy failover.
Ensure that the primary cluster is in the unavailable state.
Check the status of each standby cluster and select an appropriate standby cluster as the new primary cluster.
For more information about how to select an appropriate standby cluster, see "Lossy failover" in the OceanBase Database Administrator Guide.
obclient> SELECT CLUSTER_ROLE, PROTECTION_MODE, PROTECTION_LEVEL, CURRENT_SCN FROM V$OB_CLUSTER; +------------------+---------------------+---------------------+------------------+ | CLUSTER_ROLE | PROTECTION_MODE | PROTECTION_LEVEL | CURRENT_SCN | +------------------+---------------------+---------------------+------------------+ | PHYSICAL STANDBY | MAXIMUM PERFORMANCE | MAXIMUM PERFORMANCE | 1613813589631620 | +------------------+---------------------+---------------------+------------------+Modify the related parameters to speed up the failover.
obclient> ALTER SYSTEM SET _mini_merge_concurrency = 16; obclient> ALTER SYSTEM SET _ob_minor_merge_schedule_interval = '3s';Execute the following statement to switch the standby cluster to the primary role.
-- Set the statement timeout duration, which can be adjusted as needed. obclient> SET OB_QUERY_TIMEOUT = 100000000; obclient> ALTER SYSTEM ACTIVATE PHYSICAL STANDBY CLUSTER;Check the current cluster status and determine the system change numbers (SCNs) of the failover.
Query the
V$OB_CLUSTERandV$OB_CLUSTER_FAILOVER_INFOviews to check the cluster status and determine the SCNs of the failover.After the failover, the role of the standby cluster changes from
PHYSICAL STANDBYtoPRIMARY.STANDBY_BECAME_PRIMARY_SCNindicates the minimum failover SCN among all tenants. TheV$OB_CLUSTER_FAILOVER_INFOview records the failover data of each tenant in each failover.SYS_TABLE_SCNindicates the failover SCN of the system table.USER_TABLE_SCNindicates the failover SCN of the user table. The failover SCN of the sys tenant is meaningless.obclient> SELECT CLUSTER_ROLE, STANDBY_BECAME_PRIMARY_SCN FROM V$OB_CLUSTER; +--------------+----------------------------+ | CLUSTER_ROLE | STANDBY_BECAME_PRIMARY_SCN | +--------------+----------------------------+ | PRIMARY | 1613813589631620 | +--------------+----------------------------+ obclient> SELECT 'FAILOVER#', TENANT_ID, SYS_TABLE_SCN, USER_TABLE_SCN FROM V$OB_CLUSTER_FAILOVER_INFO; +------------------+-----------+------------------+------------------+ | FAILOVER# | TENANT_ID | SYS_TABLE_SCN | USER_TABLE_SCN | +------------------+-----------+------------------+------------------+ | 1613813770317824 | 1 | 1613813772434321 | 1613813772434321 | | 1613813770317824 | 1001 | 1613813589631620 | 1613813589631620 | | 1613813770317824 | 1002 | 1613813589631620 | 1613813589631620 | +------------------+-----------+------------------+------------------+Restore parameters.
Restore the parameters modified during failover to avoid adverse impact on subsequent cluster operations.
obclient> ALTER SYSTEM SET _mini_merge_concurrency = 5; obclient> ALTER SYSTEM SET _ob_minor_merge_schedule_interval = '20s';