Open-Source Wikis

/

CockroachDB

/

Features

/

Cross-cluster replication

cockroachdb/cockroach

Cross-cluster replication

CockroachDB supports two modes of cluster-to-cluster replication:

  • PCR (Physical Cluster Replication) — byte-for-byte streaming of MVCC for an entire tenant.
  • LDR (Logical Data Replication) — application-level streaming of row changes between two live clusters.

Both run as long-lived jobs that consume rangefeeds on the source and ingest SSTs (PCR) or apply rows (LDR) on the destination.

Code

  • pkg/crosscluster/ — shared utilities, ingestion processors, replication frontiers, conflict resolution.
  • pkg/ccl/streamingccl/ — the CCL-licensed source/sink stream producers.
  • pkg/repstream/ — typed wire format and helpers.

PCR

Used to maintain a hot standby tenant. Setup:

CREATE TENANT "secondary" FROM REPLICATION OF "primary" ON 'connection-uri';

The source cluster runs a producer job that emits a typed stream of MVCC events; the destination runs an ingestion job that re-creates the tenant's KV namespace verbatim. Cutover (ALTER TENANT secondary SET REPLICATION RESUMED) hot-swaps which side serves writes.

LDR

Used for application-level replication where the two sides may diverge. The source emits rangefeed events filtered by table; the destination decodes them, resolves conflicts (last-write-wins by default), and writes via the SQL writer (pkg/sql/sqlwriter/). Schema changes are coordinated via a control plane.

graph LR
  Source["primary"] -->|rangefeed| Producer["streamingccl producer"]
  Producer -->|stream| Network
  Network --> Ingest["crosscluster ingestion processor"]
  Ingest -->|sql writes| Dest["secondary"]

Built by Factory AutoWiki from public repository content. It is a generated preview for codebase exploration, not source-maintained documentation.

Cross-cluster replication – CockroachDB wiki | Factory