DBAtlas · 데이터베이스 운영 아틀라스

replica 승격 / 페일오버(promote)

Oracle

-- Data Guard broker (DGMGRL):
SWITCHOVER TO 'standby_db';     -- planned, no data loss
-- FAILOVER TO 'standby_db';     -- on loss of the primary, emergency

SWITCHOVER는 계획된 역할 전환이고, FAILOVER는 primary에 접근할 수 없을 때 수행하며 데이터 손실 위험이 있다.

PostgreSQL

-- Promote the standby to primary:
SELECT pg_promote();
-- or from the shell: pg_ctl promote -D /var/lib/pgsql/data

승격 전에 기존 primary가 실제로 중지되었는지 확인한다(split-brain 위험). 승격 후 기존 primary를 새 primary의 replica로 다시 합류시키려면 pg_rewind가 필요하며, 이를 위해 wal_log_hints = on 또는 데이터 체크섬이 활성화되어 있어야 한다.

MySQL

-- On the replica (manual):
-- 1) Stop receiving new events, wait until the received relay log is fully applied:
STOP REPLICA IO_THREAD;
SELECT RECEIVED_TRANSACTION_SET FROM performance_schema.replication_connection_status;
SELECT @@GLOBAL.gtid_executed;  -- the received set must be fully contained here
-- 2) Remove replication and enable writes:
STOP REPLICA;
RESET REPLICA ALL;
SET GLOBAL read_only = OFF;  -- also turns off super_read_only
-- 3) Fence the old source against writes, then redirect the application.

relay log가 모두 적용되기 전에 RESET REPLICA ALL을 실행하면 수신했지만 적용되지 않은 트랜잭션이 손실된다. replica는 보통 read_only/super_read_only가 활성화된 상태로 운영되며, 이를 끄기 전까지 쓰기가 허용되지 않는다. 기존 소스가 여전히 쓰기 가능하면 split-brain 위험이 있다. 이 구문은 8.0.22+용이다(이전에는 STOP SLAVE / RESET SLAVE ALL, 옛 형식은 8.4에서 제거됨). 운영 환경에서 자동적이고 안전한 페일오버를 원하면 InnoDB Cluster/Group Replication, Orchestrator 또는 MHA를 사용한다.

SQL Server

-- On the target secondary replica (synchronous):
ALTER AVAILABILITY GROUP [AG_Name] FAILOVER;
-- Force it, with risk of data loss:
-- ALTER AVAILABILITY GROUP [AG_Name] FORCE_FAILOVER_ALLOW_DATA_LOSS;

동기 replica로의 계획된 페일오버는 데이터 손실이 없다. FORCE는 재해 상황에서만 사용한다.

MongoDB

// Trigger an election on the current primary:
rs.stepDown(60)   // step down from primary for 60 s

stepDown은 새 선출을 시작한다. 특정 노드를 우선시하려면 멤버의 priority 값을 조정한다.

Redis

# Make the replica an independent primary:
REPLICAOF NO ONE
# With Sentinel (recommended): SENTINEL FAILOVER <master-name>

Sentinel/Cluster를 사용한다면 수동 REPLICAOF 대신 SENTINEL FAILOVER를 사용한다. 그렇지 않으면 split-brain 위험이 있다.

DBAtlas에서 열기 →