DBAtlas · Atlas für Datenbankbetrieb

Replikat hochstufen / Failover (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 ist ein geplanter Rollenwechsel; FAILOVER erfolgt, wenn der Primary nicht erreichbar ist, und birgt ein Risiko von Datenverlust.

PostgreSQL

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

Vor dem Hochstufen sicherstellen, dass der alte Primary wirklich gestoppt ist (Split-Brain-Risiko). Um den alten Primary nach dem Promote als Replikat des neuen Primary wieder einzubinden, ist pg_rewind nötig; dafür müssen wal_log_hints = on oder Data Checksums aktiviert sein.

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.

Wird RESET REPLICA ALL ausgeführt, bevor das Relay Log vollständig angewendet ist, gehen empfangene, aber nicht angewendete Transaktionen verloren. Replikate laufen meist mit aktiviertem read_only/super_read_only; Schreibzugriffe werden erst nach dem Abschalten akzeptiert. Ist die alte Source noch beschreibbar, besteht Split-Brain-Risiko. Die Syntax gilt ab 8.0.22 (davor STOP SLAVE / RESET SLAVE ALL; die alte Form wurde in 8.4 entfernt). Für automatisches und sicheres Failover in Produktion InnoDB Cluster/Group Replication, Orchestrator oder MHA bevorzugen.

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;

Ein geplantes Failover auf ein synchrones Replikat erfolgt ohne Datenverlust; FORCE wird nur im Desaster-Szenario verwendet.

MongoDB

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

stepDown startet eine neue Election; um einen bestimmten Knoten zu bevorzugen, die priority-Werte der Mitglieder anpassen.

Redis

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

Bei Einsatz von Sentinel/Cluster SENTINEL FAILOVER statt eines manuellen REPLICAOF verwenden; sonst besteht Split-Brain-Risiko.

In DBAtlas öffnen →