Promover uma réplica / fazer 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 é uma transição de papéis planejada; FAILOVER é realizado enquanto o primary está inacessível e traz risco de perda de dados.
PostgreSQL
-- Promote the standby to primary:
SELECT pg_promote();
-- or from the shell: pg_ctl promote -D /var/lib/pgsql/dataAntes de promover, certifique-se de que o antigo primary esteja realmente parado (risco de split-brain). Após a promoção, reintegrar o antigo primary como réplica do novo primary exige pg_rewind; para isso, wal_log_hints = on ou data checksums devem estar habilitados.
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.Se RESET REPLICA ALL for executado antes de o relay log ser totalmente aplicado, as transações recebidas mas não aplicadas são perdidas. As réplicas geralmente rodam com read_only/super_read_only habilitado; escritas não são aceitas até que sejam desativados. Se a antiga origem ainda aceitar escritas, há risco de split-brain. A sintaxe é do 8.0.22+ (antes, STOP SLAVE / RESET SLAVE ALL; a forma antiga foi removida no 8.4). Para failover automático e seguro em produção, prefira InnoDB Cluster/Group Replication, Orchestrator ou 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;Um failover planejado para uma réplica síncrona não tem perda de dados; FORCE é usado apenas em um cenário de desastre.
MongoDB
// Trigger an election on the current primary:
rs.stepDown(60) // step down from primary for 60 sstepDown inicia uma nova eleição; para favorecer um nó específico, ajuste os valores de priority dos membros.
Redis
# Make the replica an independent primary:
REPLICAOF NO ONE
# With Sentinel (recommended): SENTINEL FAILOVER <master-name>Se você usa Sentinel/Cluster, use SENTINEL FAILOVER em vez de um REPLICAOF manual; caso contrário, há risco de split-brain.