This feature is in and subject to change. To share feedback and/or issues, contact Support.
- Unidirectional LDR from a source table to a destination table (cluster A to cluster B) in one LDR job.
- Bidirectional LDR for the same table from cluster A to cluster B and from cluster B to cluster A. In a bidirectional setup, each cluster operates as both a source and a destination in separate LDR jobs.
CREATE LOGICALLY REPLICATED accepts unidirectional or bidirectional on as an option in order to create one of the setups automatically. Step 3 outlines when to use the CREATE LOGICALLY REPLICATED or the CREATE LOGICAL REPLICATION STREAM syntax to start LDR.
In the following diagram, LDR stream 1 creates a unidirectional LDR setup, introducing LDR stream 2 extends the setup to bidirectional.
Tutorial overview
If you’re setting up bidirectional LDR, both clusters will act as a source and a destination in the respective LDR jobs. The high-level steps for setting up bidirectional or unidirectional LDR:- Prepare the clusters with the required settings, users, and privileges according to the LDR setup.
- Set up on the destination to hold the connection URI for the source.
- Start LDR from the destination cluster with your required syntax and options.
- Check the status of the LDR job in the .
Before you begin
You’ll need:- Two separate v25.1 CockroachDB self-hosted clusters with connectivity between every node in both clusters. That is, all nodes in cluster A must be able to contact each node in cluster B and vice versa. The SQL advertised address should be the cluster node advertise address so that the LDR job can plan node-to-node connections between clusters for maximum performance. The source and destination clusters must be configured with similar hardware profiles, number of nodes, and overall size. Significant discrepancies in the cluster configurations may result in degraded performance.
- To set up each cluster, you can follow .
- The tutorial creates a self-signed certificate for each self-hosted cluster. To create certificates signed by an external certificate authority, refer to .
- All nodes in each cluster will need access to the Certificate Authority for the other cluster. Refer to Step 2. Connect from the destination to the source.
- LDR replicates at the table level, which means clusters can contain other tables that are not part of the LDR job. (For
CREATE LOGICAL REPLICATION STREAMonly): If both clusters are empty, create the tables that you need to replicate with identical schema definitions (excluding indexes) on both clusters. If one cluster already has an existing table that you’ll replicate, ensure the other cluster’s table definition matches. For more details on the supported schemas, refer to Schema Validation.
Schema validation
Before you start LDR, you must ensure that all column names, types, constraints, and unique indexes on the destination table match with the source table. You cannot use LDR on a table with a schema that contains:- and
- Indexes with a
- Composite types in the
- dependencies
CREATE LOGICALLY REPLCATED syntax, you cannot use LDR on a table with a schema that contains:
Unique secondary indexes
When the destination table includes unique , it can cause rows to enter the . The two clusters in LDR operate independently, so writes to one cluster can conflict with writes to the other. If the application modifies the same row in both clusters, LDR resolves the conflict using conflict resolution. are validated locally in each cluster, therefore if a replicated write violates aUNIQUE constraint on the destination cluster (possibly because a conflicting write was already applied to the row) the replicating row will be applied to the DLQ.
For example, consider a table with a unique name column where the following operations occur in this order in a source and destination cluster running LDR:
On the source cluster:
1 on the destination cluster is unavailable for a few minutes due to a .
Timestamp 6: On the destination cluster, LDR attempts to replicate the row (1, nyc), but it enters the retry queue for 1 minute due to the unavailable range. LDR adds 1, nyc to the DLQ table after retrying and observing the UNIQUE constraint violation:
- For unidirectional LDR, validate unique index constraints on the source cluster only.
- For bidirectional LDR, remove unique index constraints on both clusters.
Step 1. Prepare the cluster
In this step you’ll prepare the required settings and privileges for LDR.If you are setting up bidirectional LDR, you must run this step on both clusters.
-
Enter the SQL shell for both clusters in separate terminal windows:
-
Enable the
kv.rangefeed.enabledon the source cluster: -
On the destination, create a user with the who will start the LDR job:
To change the password later, refer to .
Step 2. Connect from the destination to the source
In this step, you’ll set up to store the connection string for one or both clusters. Depending on how you manage certificates, you must ensure that all nodes between the clusters have access to the certificate of the other cluster. You can use thecockroach encode-uri command to generate a connection string containing a cluster’s certificate.
-
On the source cluster in a new terminal window, generate a connection string, by passing the replication user, node IP, and port, along with the directory to the source cluster’s CA certificate:
The connection string output contains the source cluster’s certificate:
-
In the SQL shell on the destination cluster, create an using the source cluster’s connection string. Prefix the
postgresql://scheme to the connection string and replace with your external connection name:
(Optional) Bidirectional: Create the connection for LDR stream 2
(Optional) For bidirectional LDR, you’ll need to repeat creating the certificate output and the external connection for the opposite cluster. Both clusters will act as the source and destination. At this point, you’ve created an external connection for LDR stream 1, so cluster A (source) to B (destination). Now, create the same for LDR stream 2 cluster B (source) to cluster A (destination).-
On cluster B, run:
The connection string output contains the source cluster’s certificate:
-
On cluster A, create an using cluster B’s connection string (source in LDR stream 2). Prefix the
postgresql://scheme to the connection string and replace with your external connection name:
Step 3. Start LDR
In this step, you’ll start the LDR stream(s) from the destination cluster. You can replicate one or multiple tables in a single LDR job. You cannot replicate system tables in LDR, which means that you must manually apply configurations and cluster settings, such as and user permissions on the destination cluster.Syntax
LDR streams can be started using one of the following SQL statements, depending on your requirements:- New in v25.1: : Creates the new table on the destination cluster automatically, and conducts a fast, offline initial scan.
CREATE LOGICALLY REPLICATEDacceptsunidirectionalorbidirectional onas an option in order to create either one of the setups automatically. The table cannot contain a . Follow these steps for setup instructions. - : Starts the LDR stream after you’ve created the matching table on the destination cluster. If the table contains user-defined types, you must use this syntax. Allows for manual creation of unidirectional or bidirectional LDR. Follow these steps for setup instructions.
- It is necessary to use the table name for the source table and destination table in the statement.
- 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.
CREATE LOGICALLY REPLICATED
Use CREATE LOGICALLY REPLICATED to create either a unidirectional or bidirectional LDR stream automatically:
-
Unidirectional LDR: run the following from the destination cluster:
-
Bidirectional LDR: This statement will first create the LDR jobs for the first stream. You must run it from the destination cluster that does not contain the table. Once the offline initial scan completes, the reverse stream will be initialized so that the original destination cluster can send changes to the original source.
Run the following from the destination cluster (i.e, the cluster that does not have the table currently):
CREATE LOGICAL REPLICATION STREAM
Ensure you’ve created the table on the destination cluster with a matching schema definition to the source cluster table. From the destination cluster, start LDR. Use the table name for the source and destination tables:
CREATE LOGICAL REPLICATION STREAM, run the statement again but cluster B will now be the source, and cluster A will be the destination.
Step 4. Manage and monitor the LDR jobs
Once LDR has started, an LDR job will run on the destination cluster. You can , , or the LDR job with the job ID. Use to display the LDR job IDs:DB Console
You’ll access the and monitor the status and metrics for the created LDR jobs. Depending on which cluster you would like to view, follow the instructions for either the source or destination.- Access the DB Console at
http://{node IP or hostname}:8080and enter your user’s credentials. - On the source cluster, navigate to the to view a list of all jobs. Use the job Type dropdown and select Replication Producer. This will display the history retention job. This will run while the LDR job is active to protect changes to the table from until they have been replicated to the destination cluster.
- On the destination cluster, use the job Type dropdown and select Logical Replication Ingestion. This page will display the logical replication stream job. There will be a progress bar in the Status column when LDR is replicating a table with existing data. This progress bar shows the status of the initial scan, which backfills the destination table with the existing data.
- On the destination cluster, click on Metrics in the left-hand navigation menu. Use the Dashboard dropdown to select . This page shows graphs for monitoring LDR.
What’s next
- : Manage the DLQ and schema changes for the replicating tables.

