Skip to main content
Version: V1.3.0

SWITCHOVER

Description​

This statement performs a primary and standby role switch: it can turn the primary into a standby without data loss, and promote a standby to primary.

Permissions​

Executing ALTER SYSTEM SWITCHOVER requires the ALTER SYSTEM privilege for the current user. For seekdb privileges, see seekdb permission classification.

Syntax​

ALTER SYSTEM SWITCHOVER TO {STANDBY | PRIMARY} [opt_verify];

Syntax reference​

FieldDescription
STANDBYSwitches the primary to a standby without data loss.
PRIMARYPromotes the standby to primary.
opt_verifyOptional. When specified, runs a pre-check to verify that prerequisites for SWITCHOVER are met. Note: Role switches can still fail. opt_verify only validates prerequisites and helps reduce the chance of failure; it does not execute SWITCHOVER. Even if opt_verify succeeds, the following SWITCHOVER is not guaranteed to succeed.

Example​

On the primary, run primary-to-standby to turn the primary into standby seekdb_backup, then confirm the instance is a standby, role is STANDBY, and SWITCHOVER_STATUS is NORMAL.

ALTER SYSTEM SWITCHOVER TO STANDBY;
Query OK, 0 rows affected

SELECT role,log_restore_source,sync_scn,readable_scn FROM oceanbase.__all_virtual_server_stat;
+---------+----------------------+---------------------+---------------------+
| role | log_restore_source | sync_scn | readable_scn |
+---------+----------------------+---------------------+---------------------+
| STANDBY | xxx.xxx.xxx.53:16608 | 1773826477275894000 | 1773826477275894000 |
+---------+----------------------+---------------------+---------------------+
1 row in set

References​