> ## Documentation Index
> Fetch the complete documentation index at: https://cockroachlabs.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Disaster Recovery Planning

export const InternalLink = ({version, path = "", children, ...props}) => {
  let detectedVersion = version || "stable";
  if (typeof window !== 'undefined' && !version) {
    const match = window.location.pathname.match(/\/docs\/([^/]+)/);
    if (match) {
      detectedVersion = match[1];
    }
  }
  const normalizedPath = path.startsWith("/") ? path.slice(1) : path;
  return <a href={`/docs/${detectedVersion}/${normalizedPath}`} {...props}>
      {children}
    </a>;
};

CockroachDB is built to be <InternalLink path="demo-fault-tolerance-and-recovery">fault-tolerant and to recover automatically</InternalLink>, but sometimes disasters happen. A *disaster* is any event that puts your cluster at risk, and usually means your cluster is experiencing [hardware failure](#hardware-failure), [data failure](#data-failure), or has [compromised security keys](#compromised-security-keys). Having a disaster recovery plan enables you to recover quickly, while limiting the consequences.

## Hardware failure

When planning to survive hardware failures, start by determining the minimum replication factor you need based on your fault tolerance goals:

* [Single-region survivability planning](#single-region-survivability-planning)
* [Multi-region survivability planning](#multi-region-survivability-planning)

<Danger>
  Increasing the replication factor can impact write performance in that more replicas must agree to reach quorum. For more details about the mechanics of writes and the Raft protocol, see <InternalLink path="architecture/reads-and-writes-overview">Read and Writes Overview</InternalLink>.
</Danger>

<Note>
  For the purposes of choosing a replication factor, disk failure is equivalent to node failure.
</Note>

If you experience hardware failures in a cluster, the recovery actions you need to take will depend on the type of infrastructure and topology pattern used:

* [Single-region recovery](#single-region-recovery)
* [Multi-region recovery](#multi-region-recovery)

### Single-region survivability planning

The table below shows the replication factor (RF) needed to achieve the listed fault tolerance goals for a single region, cloud-deployed cluster with nodes spread as evenly as possible across 3 availability zones (AZs):

<Note>
  See our <InternalLink path="topology-basic-production#configuration">basic production topology</InternalLink> for configuration guidance.
</Note>

| Fault Tolerance Goals | 3 nodes      | 5 nodes      | 9 nodes      |
| --------------------- | ------------ | ------------ | ------------ |
| **1 Node**            | RF = 3       | RF = 3       | RF = 3       |
| **1 AZ**              | RF = 3       | RF = 3       | RF = 3       |
| **2 Nodes**           | Not possible | RF = 5       | RF = 5       |
| **AZ + Node**         | Not possible | Not possible | RF = 9       |
| **2 AZ**              | Not possible | Not possible | Not possible |

To be able to survive 2+ availability zones failing, scale to a [multi-region](#multi-region-survivability-planning) deployment.

### Single-region recovery

For hardware failures in a single-region cluster, the recovery actions vary and depend on the type of infrastructure used.

For example, consider a cloud-deployed CockroachDB cluster with the following setup:

* Single-region
* 3 nodes
* A node in each availability zone (i.e., 3 AZs)
* Replication factor of 3

The table below describes what actions to take to recover from various hardware failures in this example cluster:

| Failure           | Availability | Consequence                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 | Action to Take                                                                                                                                                                                                                                                                                                                                                                                                       |
| ----------------- | ------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **1 Disk**        | **√**        | Fewer resources are available. Some data will be under-replicated until the failed nodes are marked dead.  Once marked dead, data is replicated to other nodes and the cluster remains healthy.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             | <InternalLink path="cockroach-start">Restart the node</InternalLink> with a new disk.                                                                                                                                                                                                                                                                                                                                |
| **1 Node**        | **√**        | If the node or AZ becomes unavailable, check the <InternalLink path="ui-overview-dashboard">Overview dashboard</InternalLink> on the DB Console:<ul><li>If the down node is marked **Suspect**, try <InternalLink path="cockroach-start">restarting the node</InternalLink>.</li><li>If the down node is marked **Dead**, <InternalLink path="node-shutdown?filters=decommission#remove-a-dead-node">decommission the node</InternalLink>, wipe the store path, and then <InternalLink path="cockroach-start">rejoin it back to the cluster</InternalLink>. If the node has additional hardware issues, decommission the node and <InternalLink path="cockroach-start">add a new node</InternalLink> to the cluster. Ensure that <InternalLink path="cockroach-start#locality">locality flags are set</InternalLink> correctly upon node startup.</li></ul> |                                                                                                                                                                                                                                                                                                                                                                                                                      |
| **1 AZ**          | **√**        |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             |                                                                                                                                                                                                                                                                                                                                                                                                                      |
| **2 Nodes**       | **X**        | Cluster is unavailable.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     | <InternalLink path="cockroach-start">Restart</InternalLink> 1 of the 2 nodes that are down to regain quorum.  If you can’t recover at least 1 node, [contact Cockroach Labs support](https://support.cockroachlabs.com/) for assistance.                                                                                                                                                                             |
| **1 AZ + 1 Node** | **X**        | Cluster is unavailable.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     | <InternalLink path="cockroach-start">Restart</InternalLink> the node that is down to regain quorum. When the AZ comes back online, try restarting the node.  If you can’t recover at least 1 node, [contact Cockroach Labs support](https://support.cockroachlabs.com/) for assistance.                                                                                                                              |
| **2 AZ**          | **X**        | Cluster is unavailable.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     | When the AZ comes back online, try <InternalLink path="cockroach-start">restarting</InternalLink> at least 1 of the nodes.  You can also [contact Cockroach Labs support](https://support.cockroachlabs.com/) for assistance.                                                                                                                                                                                        |
| **3 Nodes**       | **X**        | Cluster is unavailable.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     | <InternalLink path="cockroach-start">Restart</InternalLink> 2 of the 3 nodes that are down to regain quorum.  If you can’t recover 2 of the 3 failed nodes, [contact Cockroach Labs support](https://support.cockroachlabs.com/) for assistance.                                                                                                                                                                     |
| **1 Region**      | **X**        | Cluster is unavailable.  Potential data loss between last backup and time of outage if the region and nodes did not come back online.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       | When the region comes back online, try <InternalLink path="cockroach-start">restarting the nodes</InternalLink> in the cluster.  If the region does not come back online and nodes are lost or destroyed, try <InternalLink path="restore">restoring the latest cluster backup</InternalLink> into a new cluster.  You can also [contact Cockroach Labs support](https://support.cockroachlabs.com/) for assistance. |

<Note>
  When using Kubernetes, recovery actions happen automatically in many cases and no action needs to be taken.
</Note>

### Multi-region survivability planning

<Tip>
  By default, every <InternalLink path="multiregion-overview">multi-region database</InternalLink> has a <InternalLink path="multiregion-overview#survival-goals">zone-level survival goal</InternalLink> associated with it. The survival goal setting provides an abstraction that handles the low-level details of replica placement to ensure your desired fault tolerance. The information below is still useful for legacy deployments.
</Tip>

The table below shows the replication factor (RF) needed to achieve the listed fault tolerance (e.g., survive 1 failed node) for a multi-region, cloud-deployed cluster with 3 availability zones (AZ) per region and one node in each AZ:

<Danger>
  The chart below describes the CockroachDB default behavior when locality flags are correctly set. It does not use geo-partitioning or a specific <InternalLink path="topology-patterns">topology pattern</InternalLink>. For a multi-region cluster in production, we do not recommend using the default behavior, as the cluster's performance will be negatively affected.
</Danger>

| Fault Tolerance Goals  | 3 Regions (9 Nodes Total) | 4 Regions (12 Nodes Total) | 5 Regions (15 Nodes Total) |
| ---------------------- | ------------------------- | -------------------------- | -------------------------- |
| **1 Node**             | RF = 3                    | RF = 3                     | RF = 3                     |
| **1 AZ**               | RF = 3                    | RF = 3                     | RF = 3                     |
| **1 Region**           | RF = 3                    | RF = 3                     | RF = 3                     |
| **2 Nodes**            | RF = 5                    | RF = 5                     | RF = 5                     |
| **1 Region + 1 Node**  | RF = 9                    | RF = 7                     | RF = 5                     |
| **2 Regions**          | Not possible              | Not possible               | RF = 5                     |
| **2 Regions + 1 Node** | Not possible              | Not possible               | RF = 15                    |

### Multi-region recovery

For hardware failures in a multi-region cluster, the actions taken to recover vary and depend on the type of infrastructure used.

For example, consider a cloud-deployed CockroachDB cluster with the following setup:

* 3 regions
* 3 AZs per region
* 9 nodes (1 node per AZ)
* Replication factor of 3

The table below describes what actions to take to recover from various hardware failures in this example cluster:

| Failure               | Availability | Consequence                                                                                                                                                                                                                                                                                                                                                                                                                                                                    | Action to Take                                                                                                                                                                                                                                                                                                                                                                                                      |            |       |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            |
| --------------------- | ------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------- | ----- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **1 Disk**            | **√**        | Under-replicated data. Fewer resources for workload.                                                                                                                                                                                                                                                                                                                                                                                                                           | <InternalLink path="cockroach-start">Restart the node</InternalLink> with a new disk.                                                                                                                                                                                                                                                                                                                               | **1 Node** | **√** | If the node or AZ becomes unavailable check the <InternalLink path="ui-overview-dashboard">Overview dashboard</InternalLink> on the DB Console:<ul><li>If the down node is marked **Suspect**, try <InternalLink path="cockroach-start">restarting the node</InternalLink>.</li><li>If the down node is marked **Dead**, <InternalLink path="node-shutdown?filters=decommission#remove-a-dead-node">decommission the node</InternalLink>, wipe the store path, and then <InternalLink path="cockroach-start">rejoin it back to the cluster</InternalLink>. If the node has additional hardware issues, decommission the node and <InternalLink path="cockroach-start">add a new node</InternalLink> to the cluster. Ensure that <InternalLink path="cockroach-start#locality">locality flags are set</InternalLink> correctly upon node startup.</li></ul> |
| **1 AZ**              | **√**        |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                |                                                                                                                                                                                                                                                                                                                                                                                                                     |            |       |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            |
| **1 Region**          | **√**        | Check the <InternalLink path="ui-overview-dashboard">Overview dashboard</InternalLink> on the DB Console. If nodes are marked **Dead**, <InternalLink path="node-shutdown?filters=decommission#remove-a-dead-node">decommission the nodes</InternalLink> and <InternalLink path="cockroach-start">add 3 new nodes</InternalLink> in a new region. Ensure that <InternalLink path="cockroach-start#locality">locality flags are set</InternalLink> correctly upon node startup. |                                                                                                                                                                                                                                                                                                                                                                                                                     |            |       |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            |
| **2 or More Regions** | **X**        | Cluster is unavailable.  Potential data loss between last backup and time of outage if the region and nodes did not come back online.                                                                                                                                                                                                                                                                                                                                          | When the regions come back online, try <InternalLink path="cockroach-start">restarting the nodes</InternalLink> in the cluster.  If the regions do not come back online and nodes are lost or destroyed, try <InternalLink path="restore">restoring the latest cluster backup</InternalLink> into a new cluster.  You can also [contact Cockroach Labs support](https://support.cockroachlabs.com/) for assistance. |            |       |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            |

When using Kubernetes, recovery actions happen automatically in many cases and no action needs to be taken.

## Data failure

When dealing with data failure due to bad actors, rogue applications, or data corruption, domain expertise is required to identify the affected rows and determine how to remedy the situation (e.g., remove the incorrectly inserted rows, insert deleted rows, etc.). However, there are a few actions that you can take for short-term remediation:

* If you are within the garbage collection window, [run differentials](#run-differentials).
* If you have a backup file, [restore to a point in time](#restore-to-a-point-in-time).
* If your cluster is running and you do not have a backup with the data you need, [create a new backup](#create-a-new-backup).
* To [recover from corrupted data in a database or table](#recover-from-corrupted-data-in-a-database-or-table), restore the corrupted object.

<Tip>
  To give yourself more time to recover and clean up the corrupted data, put your application in “read only” mode and only run <InternalLink path="as-of-system-time">`AS OF SYSTEM TIME`</InternalLink> queries from the application.
</Tip>

### Run differentials

If you are within the <InternalLink path="configure-replication-zones">garbage collection window</InternalLink>, run <InternalLink path="as-of-system-time">`AS OF SYSTEM TIME`</InternalLink> queries and use <InternalLink path="create-table-as">`CREATE TABLE AS … SELECT * FROM`</InternalLink> to create comparison data and run differentials to find the offending rows to fix.

If you are outside of the garbage collection window, you will need to use a <InternalLink path="backup">backup</InternalLink> to run comparisons.

### Restore to a point in time

* Use your <InternalLink path="backup">backup</InternalLink> file to <InternalLink path="take-backups-with-revision-history-and-restore-from-a-point-in-time">restore to a point in time</InternalLink> where you are certain there was no corruption. Note that the backup must have been taken with <InternalLink path="backup">revision history</InternalLink>.

### Create a new backup

If your cluster is running, you do not have a backup that encapsulates the time you want to <InternalLink path="restore">restore</InternalLink> to, and the data you want to recover is still in the <InternalLink path="configure-replication-zones">garbage collection window</InternalLink>, there are two actions you can take:

* Trigger a new <InternalLink path="take-backups-with-revision-history-and-restore-from-a-point-in-time">backup `with_revision_history`</InternalLink> and you will have a backup you can use to restore to the desired point in time within the <InternalLink path="configure-replication-zones">garbage collection window</InternalLink>.

### Recover from corrupted data in a database or table

If you have corrupted data in a database or table, <InternalLink path="restore">restore</InternalLink> the object from a prior <InternalLink path="backup">backup</InternalLink>. If revision history is in the backup, you can restore from a <InternalLink path="take-backups-with-revision-history-and-restore-from-a-point-in-time">point in time</InternalLink>.

Instead of dropping the corrupted table or database, we recommend <InternalLink path="alter-table#rename-to">renaming the table</InternalLink> or <InternalLink path="alter-database#rename-to">renaming the database</InternalLink> so you have historical data to compare to later. If you drop a database, the database cannot be referenced with `AS OF SYSTEM TIME` queries, and you will need to take a backup that is backdated to the system time when the database still existed.

<Note>
  If the table you are restoring has foreign keys, <InternalLink path="restore#remove-the-foreign-key-before-restore">careful consideration</InternalLink> should be applied to make sure data integrity is maintained during the restore process.
</Note>

## Compromised security keys

CockroachDB maintains a secure environment for your data. However, there are bad actors who may find ways to gain access or expose important security information. In the event that this happens, there are a few things you can do to get ahead of a security issue:

* If you have [changefeeds to cloud storage sinks](#changefeeds-to-cloud-storage), cancel the changefeed job and restart it with new access credentials.
* If you are using [Enterprise Encryption At Rest](#encryption-at-rest), rotate the store key(s).
* If you are using [wire encryption in transit / TLS](#wire-encryption-tls), rotate your keys.

### Changefeeds to cloud storage

1. <InternalLink path="cancel-job">Cancel the changefeed job</InternalLink> immediately and <InternalLink path="monitor-and-debug-changefeeds#monitor-a-changefeed">record the high water timestamp</InternalLink> for where the changefeed was stopped.
2. Remove the access keys from the identity management system of your cloud provider and replace with a new set of access keys.
3. <InternalLink path="create-changefeed#start-a-new-changefeed-where-another-ended">Create a new changefeed</InternalLink> with the new access credentials using the last high water timestamp.

### Encryption at rest

If you believe the user-defined store keys have been compromised, quickly attempt to rotate your store keys that are being used for your encryption at rest setup. If this key has already been compromised and the store keys were rotated by a bad actor, the cluster should be wiped if possible and <InternalLink path="restore">restored</InternalLink> from a prior backup.

If the compromised keys were not rotated by a bad actor, quickly attempt to <InternalLink path="security-reference/encryption#rotating-keys">rotate the store key</InternalLink> by restarting each of the nodes with the old key and the new key. For an example on how to do this, see <InternalLink path="encryption#changing-encryption-algorithm-or-keys">Encryption</InternalLink>.

Once all of the nodes are restarted with the new key, put in a request to revoke the old key from the Certificate Authority.

<Note>
  CockroachDB does not allow prior store keys to be used again.
</Note>

### Wire Encryption / TLS

As a best practice, <InternalLink path="rotate-certificates">keys should be rotated</InternalLink>. In the event that keys have been compromised, quickly attempt to rotate your keys. This can include rotating node certificates, client certificates, and the CA certificate.

## See also

* <InternalLink path="demo-fault-tolerance-and-recovery">Fault Tolerance & Recovery</InternalLink>
* <InternalLink path="take-full-and-incremental-backups">Back up and Restore Data</InternalLink>
* <InternalLink path="topology-patterns">Topology Patterns</InternalLink>
* <InternalLink path="recommended-production-settings">Production Checklist</InternalLink>
