DBAtlas · Atlas de operaciones de bases de datos

Configurar replicación continua / CDC (cutover sin indisponibilidad)

Oracle

# CDC-based replication with Oracle GoldenGate (outline)
# 1) Enable supplemental logging on the source:
ALTER DATABASE ADD SUPPLEMENTAL LOG DATA;
# 2) Extract (capture changes from redo) and Replicat (apply to the target) processes:
#   GGSCI> ADD EXTRACT ext1, INTEGRATED TRANLOG, BEGIN NOW
#   GGSCI> ADD REPLICAT rep1, INTEGRATED
# Alternative: initial load with Data Pump + incremental capture with GoldenGate

En Oracle, la herramienta estándar para CDC heterogéneo/sin indisponibilidad es Oracle GoldenGate: el proceso Extract captura los cambios de los redo logs y Replicat los aplica en el destino; debe estar habilitado el supplemental logging. Migración típica: la carga inicial se hace con Data Pump y, a partir de ahí, GoldenGate envía los cambios al destino, lo que permite un cutover con una indisponibilidad casi nula.

PostgreSQL

-- Source (publisher): create a publication (wal_level must be logical)
CREATE PUBLICATION migration_pub FOR ALL TABLES;

-- Target (subscriber): create a subscription (initial copy + continuous stream)
CREATE SUBSCRIPTION migration_sub
  CONNECTION 'host=source dbname=shop user=repl password=***'
  PUBLICATION migration_pub;

PostgreSQL ofrece CDC con la replicación lógica integrada: CREATE PUBLICATION en el origen, CREATE SUBSCRIPTION en el destino. Al iniciarse, la suscripción copia los datos existentes (copia inicial) y luego transmite continuamente los cambios desde el WAL; se requiere wal_level=logical. Para escenarios grandes/complejos se prefiere pglogical o Debezium.

MySQL

-- Source: binlog must be enabled and in ROW format (log_bin, binlog_format=ROW)
-- Grant a replication user: GRANT REPLICATION SLAVE ON *.* TO 'repl'@'%';

-- Define the source on the target (start from the binlog position of the initial load):
CHANGE REPLICATION SOURCE TO
  SOURCE_HOST='source', SOURCE_USER='repl', SOURCE_PASSWORD='***',
  SOURCE_LOG_FILE='binlog.000001', SOURCE_LOG_POS=1547;
START REPLICA;

En MySQL, un cutover sin indisponibilidad se hace con replicación basada en binlog. La carga inicial se obtiene con mysqldump --source-data y se registra la posición del binlog/GTID; en el destino, la replicación se inicia desde esa posición con CHANGE REPLICATION SOURCE TO (sintaxis de 8.0.23+; antes CHANGE MASTER TO). START REPLICA aplica los cambios de forma continua. Una configuración basada en GTID es más segura.

SQL Server

-- Option A: Transactional Replication (publisher->distributor->subscriber) — SSMS wizard

-- Option B: Change Data Capture (track changes as tables)
EXEC sys.sp_cdc_enable_db;              -- enable CDC at database level
EXEC sys.sp_cdc_enable_table
  @source_schema = N'dbo', @source_name = N'customer',
  @role_name = NULL;                    -- enable CDC at table level
-- Changes are read from the cdc.dbo_customer_CT table and moved to the target.

SQL Server tiene dos vías principales para la replicación continua: si quiere un flujo directo hacia el destino, configure Transactional Replication (publisher/subscriber); si va a mover los cambios con su propio ETL, habilite Change Data Capture (sp_cdc_enable_db + sp_cdc_enable_table) y lea de las tablas _CT. Para destinos heterogéneos, CDC se combina con AWS DMS/Debezium.

MongoDB

// Watch changes live with Change Streams (requires a replica set/sharded cluster)
const cs = db.customer.watch([], { fullDocument: "updateLookup" });
while (cs.hasNext()) { printjson(cs.next()); }  // apply to the target

// Official tool for managed cluster-to-cluster replication/migration: mongosync
// mongosync --cluster0 "mongodb://source" --cluster1 "mongodb://target"

En MongoDB se usan Change Streams para CDC: db.collection.watch() transmite en vivo desde el oplog los eventos insert/update/delete para aplicarlos en el destino (se requiere un replica set). Para una migración/replicación continua completa de clúster a clúster, la herramienta oficial Cluster-to-Cluster Sync de MongoDB, mongosync (no exclusiva de Atlas; también funciona con clústeres autogestionados), gestiona la carga inicial + la sincronización continua.

Redis

# Make the target instance a replica of the source (live synchronization)
# On the target Redis:
REPLICAOF source_host 6379
# Monitor sync status:
INFO replication   # master_link_status must be up

# Once the cutover is complete, make the target standalone:
REPLICAOF NO ONE

En Redis, un cutover sin indisponibilidad se hace con la replicación nativa: ejecute REPLICAOF <source host port> (antes SLAVEOF) en el servidor de destino; el destino recibe primero el RDB completo y luego se mantiene sincronizado de forma continua mediante el flujo de comandos. Verifique master_link_status:up con INFO replication y, una vez completado el cutover, convierta el destino en standalone con REPLICAOF NO ONE.

Elasticsearch

# Incremental reindex from the old cluster to the new one within the same version family
POST _reindex?wait_for_completion=false
{ "source": { "remote": { "host": "http://old:9200" }, "index": "customer",
    "query": { "range": { "updated_at": { "gt": "<last-cursor>" } } } },
  "dest": { "index": "customer" } }

# Licensed feature: Cross-Cluster Replication (CCR) — continuous following
# On the target (follower) cluster: PUT /customer/_ccr/follow { "remote_cluster": "old", "leader_index": "customer" }

La función real de replicación continua en Elasticsearch es Cross-Cluster Replication (CCR): el clúster de destino sigue al leader index del origen y extrae los cambios de forma continua (requiere una licencia comercial/Platinum). Sin licencia, se logra una sincronización casi continua con remote reindex periódico (incremental, basado en un campo de tiempo/secuencia).

Abrir en DBAtlas →