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 v25.1: The CREATE LOGICALLY REPLICATED statement starts on a table(s) that runs between a source and destination cluster in an active-active setup. CREATE LOGICALLY REPLICATED creates the new table on the destination cluster automatically and conducts a fast, offline initial scan. It accepts unidirectional or bidirectional on as an option to create either one of the setups automatically. Once the offline initial scan completes, the new table will come online and is ready to serve queries. In a setup, the second LDR stream will also initialize after the offline initial scan completes.
If the table to be replicated contains , you must use the statement instead. You can set up unidirectional or bidirectional LDR manually with CREATE LOGICAL REPLICATION STREAM.
This page is a reference for the CREATE LOGICALLY REPLICATED SQL statement, which includes information on its parameters and options. For a step-by-step guide to set up LDR, refer to the page.

Required privileges

CREATE LOGICALLY REPLICATED requires one of the following privileges:
  • The .
  • The .
Use the statement:

Synopsis

<?xml version=“1.0” encoding=“UTF-8”?>

Parameters

ParameterDescription
db_object_nameThe name of the table on the source or destination cluster. Refer to Examples.
logical_replication_resources_listA list of the table names on the source or destination cluster to include in the LDR stream. Refer to the LDR with multiple tables example.
source_connection_stringThe connection string to the source cluster. Use an to store the source cluster’s connection URI. To start LDR, run CREATE LOGICALLY REPLICATED from the destination cluster.
logical_replication_create_table_optionsOptions to modify the behavior of the LDR stream. For a list, refer to Options. Note: bidirectional on or unidirectionalis a required option. For use cases of unidirectional and bidirectional LDR, refer to the page.

Options

OptionDescription
bidirectional on / unidirectional(Required) Specifies whether the LDR stream will be unidirectional or bidirectional. With bidirectional on specified, LDR will set up two LDR streams between the clusters. Refer to the examples for unidirectional and bidirectional.
labelTracks LDR metrics at the job level. Add a user-specified string with label. For more details, refer to .

Examples

CREATE LOGICALLY REPLICATED will automatically create the specified source tables on the destination cluster. For unidirectional and bidirectional, run the statement to start LDR on the destination cluster that does not contain the tables.

Unidirectional

From the destination cluster of the LDR stream, run:
Include the following:
  • destination table name.
  • source table name.
  • for the source cluster. For instructions on creating the external connection for LDR, refer to .
  • unidirectional option.
  • Any other options.
For details on managing schema changes, conflicts, and jobs when LDR is running, refer to the page.

Bidirectional

Both clusters will act as a source and destination in bidirectional LDR setups. To start the LDR jobs, you must run this statement from the destination cluster that does not contain the tables:
Include the following:
  • destination table name.
  • source table name.
  • for the source cluster. For instructions on creating the external connection for LDR, refer to .
  • bidirectional on option defining the external connection for the destination cluster.
  • Any other options.
For details on managing schema changes, conflicts, and jobs when LDR is running, refer to the page.

Multiple tables

To include multiple tables in an LDR stream, add the fully qualified table names in a list format. Ensure that the table name in the source table list and destination table list are in the same order:
For details on managing schema changes, conflicts, and jobs when LDR is running, refer to the page.

See more