Promover una réplica / hacer failover (promote)
Oracle
-- Data Guard broker (DGMGRL):
SWITCHOVER TO 'standby_db'; -- planned, no data loss
-- FAILOVER TO 'standby_db'; -- on loss of the primary, emergencySWITCHOVER es una transición de roles planificada; FAILOVER se realiza cuando el primary no está accesible y conlleva riesgo de pérdida de datos.
PostgreSQL
-- Promote the standby to primary:
SELECT pg_promote();
-- or from the shell: pg_ctl promote -D /var/lib/pgsql/dataAntes de promover, asegúrese de que el antiguo primary esté realmente detenido (riesgo de split-brain). Tras la promoción, reincorporar el antiguo primary como réplica del nuevo primary requiere pg_rewind; para ello debe estar habilitado wal_log_hints = on o los data checksums.
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.Si se ejecuta RESET REPLICA ALL antes de que el relay log esté totalmente aplicado, se pierden las transacciones recibidas pero no aplicadas. Las réplicas suelen ejecutarse con read_only/super_read_only habilitado; no se aceptan escrituras hasta que se desactiven. Si el antiguo origen sigue admitiendo escrituras, hay riesgo de split-brain. La sintaxis es de 8.0.22+ (antes STOP SLAVE / RESET SLAVE ALL; la forma antigua se eliminó en 8.4). Para un failover automático y seguro en producción, prefiera InnoDB Cluster/Group Replication, Orchestrator o 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;Un failover planificado a una réplica síncrona no tiene pérdida de datos; FORCE solo se usa en un escenario de desastre.
MongoDB
// Trigger an election on the current primary:
rs.stepDown(60) // step down from primary for 60 sstepDown inicia una nueva elección; para favorecer un nodo concreto, ajuste los valores de priority de los miembros.
Redis
# Make the replica an independent primary:
REPLICAOF NO ONE
# With Sentinel (recommended): SENTINEL FAILOVER <master-name>Si usa Sentinel/Cluster, use SENTINEL FAILOVER en lugar de un REPLICAOF manual; de lo contrario hay riesgo de split-brain.