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
| Field | Description |
|---|---|
| STANDBY | Switches the primary to a standby without data loss. |
| PRIMARY | Promotes the standby to primary. |
| opt_verify | Optional. 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