- Failover from the primary cluster to the standby cluster.
- Failback:
- From the original standby cluster (after it was promoted during failover) to the original primary cluster.
- After the PCR stream used an existing cluster as the primary cluster.
- Job management after a failover or failback.
Failover and failback do not redirect traffic automatically to the standby cluster. Once the failover or failback is complete, you must redirect application traffic to the standby cluster.
Failover
The failover is a two-step process on the standby cluster:Before you begin
During PCR, jobs running on the primary cluster will replicate to the standby cluster. Before you fail over to the standby cluster, or fail back to the original primary cluster, consider how you will manage running (replicated) jobs between the clusters. Refer to Job management for instructions.Step 1. Initiate the failover
To initiate a failover to the standby cluster, specify the point in time for its promotion. At failover, the standby cluster’s data will reflect the state of the primary at the specified moment. Refer to the following sections for steps:LATEST: The most recent replicated timestamp. This minimizes any data loss from the replication lag in asynchronous replication.- Point-in-time:
- Past: A past timestamp within the of up to 4 hours in the past.
- Future: A future timestamp for planning a failover.
Fail over to the most recent replicated time
To initiate a failover to the most recent replicated timestamp, specifyLATEST. Due to , the most recent replicated time may be behind the current actual time. Replication lag is the time difference between the most recent replicated time and the actual time.
-
To view the current replication timestamp, use:
-
Run the following from the standby cluster’s SQL shell to start the failover:
The
failover_timeis the timestamp at which the replicated data is consistent. The cluster will revert any replicated data above this timestamp to ensure that the standby is consistent with the primary at that timestamp:
Fail over to a point in time
You can control the point in time that the PCR stream will fail over to.-
To select a in the past, use:
The
retained_timeresponse provides the earliest time to which you can fail over. This is up to four hours in the past. -
Specify a timestamp:
Refer to for more information. Similarly, to fail over to a specific time in the future:A future failover will proceed once the replicated data has reached the specified time.
To monitor for when the PCR stream completes, do the following:
- Find the PCR stream’s
job_idusingSELECT * FROM [SHOW JOBS] WHERE job_type = 'REPLICATION STREAM INGESTION'; - Run
SHOW JOB WHEN COMPLETE job_id. Refer to theSHOW JOBSpage for and an .
Step 2. Complete the failover
-
The completion of the replication is asynchronous; to monitor its progress use:
Refer to for the and of
SHOW VIRTUAL CLUSTER ... WITH REPLICATION STATUSfields. -
Once complete, bring the standby’s virtual cluster online with:
-
To make the standby’s virtual cluster the default for connection strings, set the following :
Failback
After failing over to the standby cluster, you may want to return to your original configuration by failing back to the original primary-standby cluster setup. Depending on the configuration of the primary cluster in the original PCR stream, use one of the following workflows:- From the original standby cluster (after it was promoted during failover) to the original primary cluster. If this failback is initiated within 24 hours of the failover, PCR replicates the net-new changes from the standby cluster to the primary cluster, rather than fully replacing the existing data in the primary cluster.
- After the PCR stream used an existing cluster as the primary cluster.
To move back to a different cluster that was not involved in the original PCR stream, set up a new PCR stream following the PCR guide.
Fail back to the original primary cluster
This section illustrates the steps to fail back to the original primary cluster from the promoted standby cluster that is currently serving traffic.- Cluster A = original primary cluster
- Cluster B = original standby cluster
-
To begin the failback to Cluster A, the virtual cluster must first stop accepting connections. Connect to the system virtual on Cluster A:
-
From the system virtual cluster on Cluster A, ensure that service to the virtual cluster has stopped:
-
Open another terminal window and generate a connection string for Cluster B using :
Copy the output ready for starting the PCR stream, which requires the connection string to Cluster B:
-
Connect to the system virtual cluster for Cluster B:
-
From the system virtual cluster on Cluster B, enable rangefeeds:
-
From the system virtual cluster on Cluster A, start the replication from Cluster B to Cluster A. Include the connection string for Cluster B:
This will reset the virtual cluster on Cluster A back to the time at which the same virtual cluster on Cluster B diverged from it. Cluster A will check with Cluster B to confirm that its virtual cluster was replicated from Cluster A as part of the original .
() If you want to start the PCR stream with a read-only virtual cluster on the standby after failing back to the original primary cluster, run the statement in this step with the
READ VIRTUAL CLUSTER option.-
Check the status of the virtual cluster on A:
-
From Cluster A, start the failover:
After the failover has successfully completed, it returns a
failover_timetimestamp, representing the time at which the replicated data is consistent. Note that the cluster reverts any replicated data above thefailover_timeto ensure that the standby is consistent with the primary at that time: -
From Cluster A, bring the virtual cluster online:
-
To make Cluster A’s virtual cluster the default for , set the following :
Fail back after replicating from an existing primary cluster
You can replicate data from an existing CockroachDB cluster that does not have enabled to a standby cluster with cluster virtualization enabled. For instructions on setting up a PCR in this way, refer to . After a failover to the standby cluster, you may want to set up PCR from the original standby cluster, which is now the primary, to another cluster, which will become the standby. There are multiple ways to set up a new standby, and some considerations. In the example, the clusters are named for reference:- A = The original primary cluster, which started without virtualization.
- B = The original standby cluster, which started with virtualization.
- You run a PCR stream from cluster A to cluster B.
- You initiate a failover from cluster A to cluster B.
- You promote the
mainvirtual cluster on cluster B and start serving application traffic from B (that acts as the primary). - You need to create a standby cluster for cluster B to replicate changes to. You can do one of the following:
- (
main) on cluster A from the replication of cluster B. Cluster A is now virtualized. This will start an initial scan because the PCR stream will ignore the former workload tables in the system virtual cluster that were . You can that were in the system virtual cluster, because the new virtual cluster will now hold the workload replicating from cluster B. - C and a
mainvirtual cluster on it from the replication of cluster B. This will start an initial scan because cluster C is empty.
- (
Job management
During PCR, jobs running on the primary cluster replicate to the standby cluster. Once you have completed a failover (or a failback), refer to the following sections for details on resuming jobs on the promoted cluster.Backup schedules
pause after failover on the promoted standby cluster. Take the following steps to resume jobs:- Verify that there are no other schedules running backups to the same , i.e., the schedule that was running on the original primary cluster.
- the backup schedule on the promoted cluster.
If your backup schedule was created on a cluster in v23.1 or earlier, it will not pause automatically on the promoted cluster after failover. In this case, you must the schedule manually on the promoted cluster and then take the outlined steps.
Changefeeds
Currently running will fail on the promoted cluster immediately after failover to avoid two clusters running the same changefeed to one sink. We recommend that you recreate changefeeds on the promoted cluster. To avoid multiple clusters running the same schedule concurrently, will after physical cluster replication has completed.If your changefeed schedule was created on a cluster in v24.1 or earlier, it will not pause automatically on the promoted cluster after failover. In this case, you will need to manage or the schedule on the promoted standby cluster to avoid two clusters running the same changefeed to one sink.

