Molt Replicator

作者 cockroachdb6c96c6394a61無授權條款4 個星標收錄於 2026年10月8日更新於 2026年10月8日儲存庫2 個月前更新

Guide for using the CockroachDB replicator to continuously replicate changes from PostgreSQL, MySQL, or Oracle to CockroachDB after an initial molt fetch data load. Use when setting up CDC replication, configuring pglogical/mylogical/oraclelogminer, or managing the fetch → replicator cutover workflow.

僅含說明DevOps & Cloud
AI 產生的概覽

指導使用 molt replicator 將 PostgreSQL、MySQL 或 Oracle 的變更持續複寫到 CockroachDB。

功能
此技能說明如何執行 CockroachDB replicator——一個獨立於 molt 的執行檔,用來把 PostgreSQL、MySQL、Oracle、Kafka、物件儲存或 CockroachDB CDC 的變更持續複寫到目標 CockroachDB 叢集。內容涵蓋 fetch 到 replicator 的切換流程、pglogical、mylogical 與 oraclelogminer 的來源端設定、關鍵命令列參數、透過 Prometheus 指標進行監控,以及維運注意事項。它產出的是設定與命令指引,而非檔案或程式碼。
適用情境
適用於在 molt fetch 完成初始大量載入後,建置寫入 CockroachDB 的變更資料擷取複寫。也適用於設定 pglogical、mylogical 或 oraclelogminer 來源端,以及管理 fetch 到 replicator 的切換與延遲監控。
執行需求
需要獨立的 replicator 執行檔(不屬於 molt)以及一個暫存 CockroachDB 資料庫。來源資料庫必須支援邏輯複寫,並需要來源端、暫存端與目標端的連線認證資訊。需要存取來源端、目標端與指標端點的网络。此技能不附帶指令碼,僅為說明文件,並含一份參數參考文件。

molt replicator

Continuous change-data-capture (CDC) replication from source databases to CockroachDB. Run after molt fetch completes the initial bulk load.

Important: replicator is a separate binary from molt. It is not invoked by molt fetch. The data-load-and-replication mode in molt fetch is deprecated — use replicator directly instead.

Architecture

Source DB ──► [replicator] ──► Staging DB (_replicator schema) ──► Target CockroachDB                  ▲            Publication/            Slot/BinLog/            LogMiner

Replicator reads changes from the source, buffers them in a staging schema on the target CRDB cluster, and applies them to the target tables.

Subcommands by Source

SourceCommand
PostgreSQLreplicator pglogical
MySQLreplicator mylogical
Oraclereplicator oraclelogminer
Kafkareplicator kafka
Cloud storagereplicator objstore
CockroachDB CDCreplicator start

Full Fetch → Replicator Workflow

Step 1: Initial bulk load with molt fetch

drop-on-target-and-recreate drops any existing target tables first; run this only against a fresh or empty target.

bash
molt fetch \  --source "postgresql://<user>:<password>@source:5432/db" \  --target "postgresql://root@crdb:26257/db" \  --bucket-path "s3://mybucket/migration" \  --table-handling drop-on-target-and-recreate

Step 2: Create publication on source (PostgreSQL)

sql
-- Run on source PostgreSQL:CREATE PUBLICATION molt_fetch FOR ALL TABLES;-- (molt fetch may have already created this; check first)

Step 3: Create staging database on target

sql
-- Run on target CockroachDB:CREATE DATABASE _replicator;

Step 4: Test connectivity

bash
# preflight only takes --stagingConn and --targetConn (always required for the# target; stagingConn required if the target is not CRDB)replicator preflight \  --stagingConn "postgresql://root@crdb:26257/_replicator" \  --targetConn "postgresql://root@crdb:26257/db"

Step 5: Start replicator

bash
replicator pglogical \  --publicationName "molt_fetch" \  --sourceConn "postgresql://<user>:<password>@source:5432/db" \  --stagingConn "postgresql://root@crdb:26257/_replicator" \  --stagingSchema "_replicator.public" \  --targetConn "postgresql://root@crdb:26257/db" \  --targetSchema "public" \  --metricsAddr "0.0.0.0:8080"

Step 6: Monitor lag

bash
curl http://localhost:8080/metrics | grep replicator_# Watch for: mutations applied, unapplied mutations, lag

Step 7: Cutover

  1. When lag reaches ~0, redirect app writes to CockroachDB
  2. Let replicator drain remaining changes
  3. Confirm no new writes on source
  4. Stop replicator
  5. Decommission the source only after molt verify passes and a source backup is confirmed

Source-Specific Setup

PostgreSQL (pglogical)

Source prerequisites:

  • User with REPLICATION privilege
  • Logical replication enabled (wal_level = logical)
  • Publication exists (created by molt fetch or manually)
bash
replicator pglogical \  --publicationName "molt_fetch" \  --slotName "replicator" \  --sourceConn "postgresql://..." \  --stagingConn "postgresql://root@crdb:26257/_replicator" \  --stagingSchema "_replicator.public" \  --targetConn "postgresql://root@crdb:26257/db" \  --targetSchema "public"

MySQL (mylogical)

Source prerequisites:

  • Binary logging enabled (binlog_format = ROW)
  • GTID mode on (gtid_mode=ON, enforce_gtid_consistency=ON)
  • User with REPLICATION CLIENT privilege
bash
replicator mylogical \  --sourceConn "mysql://<user>:<password>@source:3306/db" \  --stagingConn "postgresql://root@crdb:26257/_replicator" \  --stagingSchema "_replicator.public" \  --targetConn "postgresql://root@crdb:26257/db" \  --targetSchema "public"

Oracle (oraclelogminer)

Source prerequisites:

  • Archive log mode enabled
  • Supplemental logging enabled
  • LogMiner permissions granted
bash
replicator oraclelogminer \  --sourceConn "oracle://<user>:<password>@oracle:1521/db" \  --stagingConn "postgresql://root@crdb:26257/_replicator" \  --stagingSchema "_replicator.public" \  --targetConn "postgresql://root@crdb:26257/db" \  --targetSchema "public"

Key Flags

bash
# Performance--parallelism 16          # concurrent DB transactions (default: 16)--flushSize 1000          # rows per batch (default: 1000)--flushPeriod 1s          # flush interval (default: 1s)
# Staging connection pool--stagingMaxPoolSize 128--stagingIdleTime 1m--stagingMaxLifetime 5m
# Target connection pool--targetMaxPoolSize 128--targetStatementCacheSize 128
# Retry--maxRetries 10--retryInitialBackoff 25ms--retryMaxBackoff 2s
# Monitoring--metricsAddr "0.0.0.0:8080"    # Prometheus metrics endpoint--schemaRefresh 1m               # refresh schema cache (0 = disabled)
# Dead letter queue (failed rows instead of stopping)--dlqTableName "replicator_dlq"
# Logging-v                               # debug-vv                              # trace--logFormat fluent                # for log aggregators--logDestination "/var/log/replicator.log"

Gotchas

  • Staging schema (_replicator.public) is auto-created by replicator, but the database (_replicator) must exist first
  • --publicationName and --slotName must match what molt fetch created. molt fetch's --pglogical-publication-name defaults to molt_fetch and its --pglogical-replication-slot-name has no default; on the replicator side, --publicationName has no default and --slotName defaults to replicator. If the names don't line up, set both explicitly on both sides.
  • DLQ table grows over time — monitor and purge failed rows periodically
  • Replicator holds an open replication slot on the source — this blocks WAL cleanup; monitor source disk usage
  • Graceful shutdown respects --gracePeriod (default: 30s); don't SIGKILL without it
  • No built-in alerting — set up external alerts on the Prometheus metrics endpoint
  • Long cutover windows increase replication lag — plan for a maintenance window if needed

See flags reference [blocked] for the full flag list.

來源與署名

來源:cockroachdb/claude-plugin位於skills/cockroachdb-onboarding-and-migrations/molt-replicator提交6c96c63

授權條款: 無授權條款

內容歸原作者所有。SourceWeft 從公開儲存庫中收錄這些內容。

檢舉或申請下架