Skip to main content
This feature is in and subject to change. To share feedback and/or issues, contact Support.
Logical data replication is only supported in CockroachDB self-hosted clusters. New in v24.3: The CREATE LOGICAL REPLICATION STREAM statement starts that runs between a source and destination cluster in an active-active setup. This page is a reference for the CREATE LOGICAL REPLICATION STREAM SQL statement, which includes information on its parameters and possible options. For a step-by-step guide to set up LDR, refer to the page.

Required privileges

CREATE LOGICAL REPLICATION STREAM requires one of the following privileges:
  • The .
  • The .
Use the statement:

Synopsis

xml version=“1.0” encoding=“UTF-8”? SQL syntax diagram

Parameters

Options

Bidirectional LDR

Bidirectional LDR consists of two clusters with two LDR jobs running in opposite directions between the clusters. If you’re setting up , both clusters will act as a source and a destination in the respective LDR jobs. LDR supports starting with two empty tables, or one non-empty table. LDR does not support starting with two non-empty tables. When you set up bidirectional LDR, if you’re starting with one non-empty table, start the first LDR job from empty to non-empty table. Therefore, you would run CREATE LOGICAL REPLICATION STREAM from the destination cluster where the non-empty table exists.

Examples

To start LDR, you must run the CREATE LOGICAL REPLICATION STREAM statement from the destination cluster. Use the . The following examples show statement usage with different options and use cases.

Start an LDR stream

There are some tradeoffs between enabling one table per LDR job versus multiple tables in one LDR job. Multiple tables in one LDR job can be easier to operate. For example, if you pause and resume the single job, LDR will stop and resume for all the tables. However, the most granular level observability will be at the job level. One table in one LDR job will allow for table-level observability.

Single table

Multiple tables

Ignore row-level TTL deletes

If you would like to ignore deletes in a unidirectional LDR stream, set the on the table. On the source cluster, alter the table to set the table storage parameter:
When you start LDR on the destination cluster, include the discard = ttl-deletes option in the statement:

See also