Skip to main content
Version: V1.4.1

SWITCHOVER

Description​

ALTER SYSTEM SWITCHOVER performs a planned role change. A standby can be promoted online to a primary. When a primary is demoted to a standby, the running process only blocks writes and persists the target role; the standby role becomes active after restart.

Privilege requirements​

The current user must have the ALTER SYSTEM privilege. For more information, see Privilege classification.

Syntax​

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

Parameters​

ParameterDescription
STANDBYStops accepting writes on the primary, waits for transactions and log appends to complete, and persists PENDING_ROLE=STANDBY. The running process continues to report ROLE=PRIMARY and becomes a standby only after restart.
PRIMARYPromotes the current standby online to a primary. Before execution, verify that the standby has synchronized to the planned switchover SCN.
VERIFYChecks the execution conditions only. It does not block writes, modify metadata, or change roles. A successful check does not guarantee that the subsequent operation will succeed.

Examples​

Execute the following statements on the original primary:

ALTER SYSTEM SWITCHOVER TO STANDBY VERIFY;
ALTER SYSTEM SWITCHOVER TO STANDBY;

SELECT ROLE, PENDING_ROLE, SWITCHOVER_STATUS
FROM oceanbase.__all_virtual_server_stat;

The expected state is:

ROLE=PRIMARY
PENDING_ROLE=STANDBY
SWITCHOVER_STATUS=PREPARING

Execute the following statements on the standby after it has caught up:

ALTER SYSTEM SWITCHOVER TO PRIMARY VERIFY;
ALTER SYSTEM SWITCHOVER TO PRIMARY;

SELECT ROLE, SYNC_SCN, READABLE_SCN
FROM oceanbase.V$OB_SERVER_STAT;

After promotion succeeds, ROLE is PRIMARY. Update the upstream configuration of the original primary and restart it to activate the persisted STANDBY role.

For the complete procedure, see Switch roles.