DBAtlas · Atlas de operações de banco de dados

Configurar replicação contínua / CDC (cutover sem downtime)

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

No Oracle, a ferramenta padrão para CDC sem downtime/heterogêneo é o Oracle GoldenGate: o processo Extract captura as alterações dos redo logs e o Replicat as aplica no destino; o supplemental logging deve estar habilitado. Migração típica: a carga inicial é feita com Data Pump e, a partir daí, o GoldenGate transmite as alterações para o destino, permitindo um cutover com downtime próximo de zero.

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;

O PostgreSQL fornece CDC com a logical replication nativa: CREATE PUBLICATION na origem, CREATE SUBSCRIPTION no destino. Quando a subscription inicia, copia os dados existentes (initial copy) e depois transmite continuamente as alterações a partir do WAL; wal_level=logical é obrigatório. Para cenários grandes/complexos, prefere-se pglogical ou 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;

No MySQL, um cutover sem downtime é feito com replicação baseada em binlog. A carga inicial é feita com mysqldump --source-data e a posição do binlog/GTID é registrada; no destino, a replicação é iniciada a partir dessa posição com CHANGE REPLICATION SOURCE TO (sintaxe do 8.0.23+; antes CHANGE MASTER TO). START REPLICA aplica as alterações continuamente. Uma configuração baseada em GTID é mais 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.

O SQL Server tem dois caminhos principais para replicação contínua: se você quer um fluxo direto para o destino, configure a Transactional Replication (publisher/subscriber); se vai mover as alterações com seu próprio ETL, habilite o Change Data Capture (sp_cdc_enable_db + sp_cdc_enable_table) e leia das tabelas _CT. Para destinos heterogêneos, o CDC é combinado com 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"

No MongoDB, usam-se Change Streams para CDC: db.collection.watch() transmite ao vivo, a partir do oplog, os eventos de insert/update/delete a serem aplicados no destino (é necessário um replica set). Para migração/replicação contínua completa de cluster para cluster, a ferramenta oficial Cluster-to-Cluster Sync do MongoDB, o mongosync (não é exclusivo do Atlas; também funciona com clusters autogerenciados), gerencia a carga inicial + a sincronização contínua.

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

No Redis, um cutover sem downtime é feito com a replicação nativa: execute REPLICAOF <source host port> (antes SLAVEOF) no servidor de destino; o destino primeiro recebe o RDB completo e depois permanece sincronizado continuamente pelo fluxo de comandos. Verifique master_link_status:up com INFO replication e, concluído o cutover, torne o destino standalone com 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" }

O recurso real de replicação contínua no Elasticsearch é o Cross-Cluster Replication (CCR): o cluster de destino segue o leader index na origem e puxa as alterações continuamente (requer licença comercial/Platinum). Sem licença, obtém-se uma sincronização quase contínua com remote reindex periódico (incremental, baseado em um campo de tempo/sequência).

Abrir no DBAtlas →