RESTORE restores your cluster’s schemas and data from stored on services such as AWS S3, Google Cloud Storage, or NFS.
Because CockroachDB is designed with high fault tolerance, restores are designed primarily for disaster recovery, i.e., restarting your cluster if it loses a majority of its nodes. Isolated issues (such as small-scale node outages) do not require any intervention.
You can restore:
For details on restoring across versions of CockroachDB, see .
The BACKUP... TO and RESTORE... FROM {storage_uri} syntax has been removed from CockroachDB v24.3 and later.
For details on the syntax to run BACKUP and RESTORE, refer to the and restore examples.
Considerations
RESTOREcannot restore backups made by newer versions of CockroachDB.RESTOREonly supports backups taken on a cluster on a specific major version into a cluster that is on the same version or the next major version. Refer to the page for more detail.RESTOREis a blocking statement. To run a restore job asynchronously, use theDETACHEDoption.RESTOREno longer requires an Enterprise license, regardless of the options passed to it or to the backup it is restoring.- You cannot restore a backup of a multi-region database into a single-region database.
- When the parameter is set on a table, the table will not contain row data when restored.
- During a , any present on the destination cluster are overwritten with the zone configurations from the . If no customized zone configurations were on the cluster when the backup was taken, then after the restore the destination cluster will use the zone configuration from the .
Required privileges
Starting in v22.2, CockroachDB introduces a new restore privilege model that provides finer control over a user’s privilege to restore backups.There is continued support for the legacy privilege model in v22.2, however it will be removed in a future release of CockroachDB. We recommend implementing the new privilege model that follows in this section for all restores.
You can grant the
RESTORE privilege to a user or role depending on the type of restore required:| Restore | Privilege |
|---|---|
| Cluster | Grant a user the system level RESTORE privilege. For example, GRANT SYSTEM RESTORE TO user;. |
| Database | Grant a user the system level RESTORE privilege to restore databases onto the cluster. For example, GRANT SYSTEM RESTORE TO user;. |
| Table | Grant a user the database level RESTORE privilege to restore schema objects into the database. For example, GRANT RESTORE ON DATABASE nonadmin TO user;. |
RESTORE privilege on a database to apply to all newly created tables in that database, use . You can add RESTORE to the user or role’s default privileges with .
Members of the can run all three types of restore (cluster, database, and table) without the need to grant a specific RESTORE privilege. However, we recommend using the RESTORE privilege model to create users or roles and grant them RESTORE privileges as necessary for stronger access control.
Privileges for managing a restore job
To manage a restore job with , , or , users must have at least one of the following:- Be a member of the .
- The .
- The , which allows you to view all jobs (including
admin-owned jobs). - Be a member of the .
- The .
Required privileges using the legacy privilege model
The following details the existing privilege model that CockroachDB supports in v22.2 and earlier. Support for this privilege model will be removed in a future release of CockroachDB:- Full cluster restores can only be run by members of the . By default, the
rootuser belongs to theadminrole. - For all other restores, the user must have (
CREATEorINSERT) on all objects affected.
Source privileges
You can grant a user theEXTERNALIOIMPLICITACCESS to interact with external resources that require implicit access.
Either the EXTERNALIOIMPLICITACCESS or the role is required for the following scenarios:
- To interact with a cloud storage resource using .
- Use of a custom endpoint on S3.
- Interacting with an Amazon S3 and Google Cloud Storage resource using
SPECIFIEDcredentials. Azure Storage is alwaysSPECIFIEDby default. - Using storage.
While Cockroach Labs actively tests Amazon S3, Google Cloud Storage, and Azure Storage, we do not test (e.g., MinIO, Red Hat Ceph).
Synopsis
Parameters
| Parameter | Description | |
|---|---|---|
table\_pattern | The table, , or you want to restore. For details on how restore works with objects that are dependent on one another, refer to Object dependencies. | |
database\_name | The name of the database you want to restore (i.e., restore all tables and views in the database). You can restore an entire database only if you had backed up the entire database. | |
string\_or\_placeholder | One of the following:
| |
string\_or\_placeholder\_opt\_list | One of the following:
| |
timestamp | Restore data as it existed as of . You can restore point-in-time data if you had taken a full or incremental backup . If the backup was not taken with revision\_history, you can use to restore to a time that the backup covers (including in the full or incremental backup). Refer to the Restore with as of system time example. | |
restore\_options\_list | Control the backup job behavior with these options. |
Options
You can controlRESTORE behavior using any of the following in the restore_options_list. To set multiple RESTORE options, use a comma-separated list:
| Option | Value | Description | |
|---|---|---|---|
DETACHED | N/A | When RESTORE runs with DETACHED, the job will execute asynchronously. The job ID is returned after the restore job creation completes. Note that with DETACHED specified, further job information and the job completion status will not be returned. For more on the differences between the returned job data, see the below. To check on the job status, use the statement. To run a restore within a , use the DETACHED option. | |
encryption\_passphrase | Passphrase used to create the | The passphrase used to decrypt the file(s) that were encrypted by the statement. | |
EXECUTION LOCALITY | Key-value pairs | Restricts the execution of the restore to nodes that match the defined requirements. Example: WITH EXECUTION LOCALITY = 'region=us-west-1a,cloud=aws' | |
incremental\_location | Restore an incremental backup from the alternate collection URI the backup was originally taken with. See Restore incremental backups for more detail. | ||
into\_db | Database name | Use to change the destination database for table restores. The destination database must exist before a restore with into\_db. (Does not apply to database or cluster restores.) Example: WITH into\_db = 'newdb' | |
kms | The URI of the cryptographic key stored in a key management service (KMS), or a comma-separated list of key URIs, used to . Refer to on the Encrypted Backups page. The key or keys are used to encrypt the manifest and data files that the BACKUP statement generates, decrypt them during a operation, and list the contents of the backup when using . AWS KMS, Google Cloud KMS, and Azure Key Vault are supported. | ||
new\_db\_name | Database name | Rename a database during a restore. The existing backed-up database can remain active while the same database is restored with a different name. Example: RESTORE DATABASE movr ... WITH new\_db\_name = 'new\_movr' | |
schema\_only | N/A | Verify that a backup is valid by running RESTORE ... schema\_only, which will restore the backed-up schema without any user data. Refer to for detail and an example. | |
skip\_localities\_check | N/A | Use to skip checking localities of a cluster before a restore when there are mismatched between the backup’s cluster and the destination cluster. For further details, refer to Restoring to multi-region databases. Example: WITH skip\_localities\_check | |
skip\_missing\_foreign\_keys | N/A | Use to remove the missing constraints before restoring. Example: WITH skip\_missing\_foreign\_keys | |
skip\_missing\_sequences | N/A | Use to ignore dependencies (i.e., the DEFAULT expression that uses the sequence). Example: WITH skip\_missing\_sequences | |
skip\_missing\_sequence\_owners | N/A | Must be used when restoring either a table that was previously a or a sequence that was previously owned by a table. Example: WITH skip\_missing\_sequence\_owners | |
skip\_missing\_udfs | N/A | Must be used when restoring a table with referenced dependencies. Any column’s DEFAULT expression using UDFs is dropped. Example: WITH skip\_missing\_udfs | |
skip\_missing\_views | N/A | Use to skip restoring that cannot be restored because their dependencies are not being restored at the same time. Example: WITH skip\_missing\_views | |
verify\_backup\_table\_data | N/A | Run a schema\_only restore and have the restore read all user data from external storage, verify checksums, and discard the user data before writing it to disk. You must also include the schema\_only option in the RESTORE statement with verify\_backup\_table\_data. For more detail, see . |
Backup file URLs
CockroachDB uses the URL provided to construct a secure API call to the service you specify. The URL structure depends on the type of file storage you are using. For more information, see the following:HTTP storage is not supported for
BACKUP and RESTORE.Functional details
CockroachDB uses checksums to ensure data integrity during both the processes. When data is , CockroachDB calculates and stores checksums with the data. The checksums are then used to verify the integrity of the data when it is read back from disk. A restore job reads the data from the external backup storage and verifies the checksums to ensure that the data has not been corrupted during the storage or transfer of the backup. You can restore:RESTORE will only restore the latest data in an object (table, database, cluster), or the latest data as per an AS OF SYSTEM TIME restore. That is, a restore will not include historical data even if you ran your backup with . This means that if you issue an AS OF SYSTEM TIME query on a restored object, the query will fail or the response will be incorrect because there is no historical data to query. For example, if you restore a table at 2022-07-13 10:38:00, it is not then possible to read or that table at 2022-07-13 10:37:00 or earlier. This is also the case for backups with revision_history that might try to initiate a revision start time earlier than 2022-07-13 10:38:00.
You can exclude a table’s row data from a backup using the parameter. With this parameter set, a table will be empty when restored.
Full cluster
A full cluster restore can only be run on a destination cluster with no user-created databases or tables. Restoring a full cluster includes:- All user tables
- Relevant system tables
- All
- All (which automatically includes their )
- All
- will be restored to their original database during a full cluster restore.
- The restore will drop the cluster’s
defaultdbandpostgresbefore the restore begins. You can only restoredefaultdbandpostgresif they are present in the original . - will not resume automatically on the new cluster. It is necessary to manually after a full-cluster restore.
- When the cluster is in a mixed-version state during an , a full cluster restore will fail. To perform a full cluster restore, it is necessary to first .
When you restore a full cluster with an Enterprise license, it will restore the of the cluster you are restoring from. If you want to use a different license in the new cluster, make sure to after the restore is complete.
Databases
Restoring a database will create a new database and restore all of its tables and views. The created database will have the name of the database in the backup.new_db_name option with RESTORE to provide a new name for the database. See the Rename a database on restore example.
If or an existing database is not an option, you can use table restore to restore all tables into the existing database by using the WITH into_db option.
Tables
You can also restore individual tables (which automatically includes their indexes), , or from a backup. This process uses the data stored in the backup to create entirely new tables, views, and sequences in the destination database. By default, tables, views, and sequences are restored into a destination database matching the name of the database from which they were backed up. If the destination database does not exist, you must . You can choose to change the destination database with theinto_db option.
The destination database must not have tables, views, or sequences with the same name as the the object you’re restoring. If any of the restore destination’s names are being used, you can:
- , , or and then restore them. Note that a sequence cannot be dropped while it is being used in a column’s
DEFAULTexpression, so those expressions must be dropped before the sequence is dropped, and recreated after the sequence is recreated. Thesetvalcan be used to set the value of the sequence to what it was previously. - Restore the table, view, or sequence into a different database.
RESTORE only offers table-level granularity; it does not support restoring subsets of a table.- If there is not an existing type in the cluster with the same name, CockroachDB will create the user-defined type as it exists in the backup.
- If there is an existing type in the cluster with the same name that is compatible with the type in the backup, CockroachDB will map the type in the backup to the type in the cluster.
- If there is an existing type in the cluster with the same name but it is not compatible with the type in the backup, the restore will not succeed and you will be asked to resolve the naming conflict. You can do this by either or the existing user-defined type.
CREATE TYPE t1 AS ENUM ('yes', 'no')andCREATE TYPE t2 AS ENUM ('yes', 'no')are compatible.CREATE TYPE t1 AS ENUM ('yes', 'no')andCREATE TYPE t2 AS ENUM ('no', 'yes')are not compatible.CREATE TYPE t1 AS ENUM ('yes', 'no')andCREATE TYPE t2 AS ENUM ('yes'); ALTER TYPE t2 ADD VALUE ('no')are not compatible because they were not created in the same way.
Object dependencies
Dependent objects must be restored at the same time as the objects they depend on. When you back up a table, it will not include any dependent tables, , or . For example, if you back upv that depends on table t, it will only back up v, not t. When you try to restore v, the restore will fail because the referenced table is not present in the backup.
Alternatively, you can pass a skip option with RESTORE to skip the dependency instead:
| Dependent object | Depends on | Skip option |
|---|---|---|
| Table with constraints | The table it REFERENCES. | |
| Table with a | The sequence. | |
The tables used in the view’s SELECT statement. |
Referenced UDFs are not restored and require the
skip_missing_udfs option.Users and privileges
The owner of restored objects will be the user running the restore job. To restore your users and privilege , you can do a cluster backup and restore the cluster to a fresh cluster with no user data. If you are not doing a full cluster restore, the table-level privileges need to be granted to the users after the restore is complete. (By default, the user restoring will become the owner of the restored objects.) To grant table-level privileges after a restore, backup thesystem.users table, , and then the table-level privileges.
Restore types
You can either restore from a full backup or from a full backup with incremental backups, based on the backup files you include:| Restore Type | Parameters |
|---|---|
| Full backup | Include the path to the full backup destination and the subdirectory of the backup. See the Examples section for syntax of cluster, database, and table restores. |
| Full backup + incremental backups | Include the path that contains the backup collection and the subdirectory containing the incremental backup. See Restore from incremental backups for an example. |
CockroachDB does not support incremental-only restores.
Performance
- The
RESTOREprocess minimizes its impact to the cluster’s performance by distributing work to all nodes. Subsets of the restored data (known as ranges) are evenly distributed among randomly selected nodes, with each range initially restored to only one node. Once the range is restored, the node begins replicating it others. - When a
RESTOREfails or is canceled, partially restored data is properly cleaned up. This can have a minor, temporary impact on cluster performance. - A restore job will pause if a node in the cluster runs out of disk space. See Viewing and controlling restore jobs for information on resuming and showing the progress of restore jobs. For instructions on how to free up disk space as quickly as possible after dropping a table, see
- A restore job will instead of entering a
failedstate if it continues to encounter transient errors once it has retried a maximum number of times. Once the restore has paused, you can either or it.
Restoring to multi-region databases
Restoring to a is supported with some limitations. This section outlines details and settings that should be considered when restoring into multi-region databases:- A will be checked before a restore. Mismatched regions between backup and restore clusters will be flagged before the restore begins, which allows for a decision between updating the or restoring with the
skip_localities_checkoption to continue with the restore regardless.
Restoring a multi-region cluster into a single-region CockroachDB Standard or CockroachDB Basic cluster is not supported. Standard and CockroachDB Basic clusters do not support the
skip_localities_check option with RESTORE. To restore a multi-region cluster, you must with regions that match the backed-up multi-region cluster.- A database that is restored with the
sql.defaults.primary_regionwill have the from this cluster setting assigned to the destination database. RESTOREsupports restoring non-multi-region tables into a multi-region database and sets the table locality as to the primary region of the destination database.- Restoring tables from multi-region databases with table localities set to ,
REGIONAL BY TABLE, , and to another multi-region database is supported. - When restoring a
REGIONAL BY TABLE IN PRIMARY REGIONtable, if the primary region is different in the source database to the destination database this will be implicitly changed on restore. - Restoring a of a
REGIONAL BY ROWtable is not supported. - and tables can be restored only if the regions of the backed-up table match those of the destination database. All of the following must be true for
RESTOREto be successful:- The of the source database and the regions of the destination database have the same set of regions.
- The regions were added to each of the databases in the same order.
-
The databases have the same .
The following example would be considered as having mismatched regions because the database regions were not added in the same order and the primary regions do not match.
Running on the source database:
Running on the destination database:In addition, the following scenario has mismatched regions between the databases since the regions were not added to the database in the same order. Running on the source database:Running on the destination database:
Use instead of the
sql.defaults.* . This allows you to set a default value for all users for any that applies during login, making the sql.defaults.* cluster settings redundant.Viewing and controlling restore jobs
After CockroachDB successfully initiates a restore, it registers the restore as a job, which you can view with . After the restore has been initiated, you can control it with , , and .If initiated correctly, the statement returns when the restore is finished or if it encounters an error. In some cases, the restore can continue after an error has been returned (the error message will tell you that the restore has resumed in background).
Examples
There are two ways to specify a full or incremental backup to restore: Some of the examples in this section use an to represent the external storage URI. For guidance on connecting to cloud storage or using other authentication parameters, read . If you need to limit the control specific users have over your storage buckets, refer to for setup instructions.View the backup subdirectories
BACKUP... INTO adds a backup to a location. To view the backup paths in a given collection location, use :
/2023/12/21-142943.73) to the RESTORE statement. For details on viewing the most recent backup, see .
Restore the most recent full or incremental backup
To restore from the most recent backup () in the collection’s location, use theLATEST syntax:
RESTORE will re-validate when are created from an older version (v20.2.2 and earlier or v20.1.4 and earlier), but restored by a newer version (v21.1.0+). These earlier releases may have included incomplete data for indexes that were in the process of being created.Restore a specific full or incremental backup
To restore a specific full or incremental backup, specify that backup’s subdirectory in theRESTORE statement. To view the available subdirectories, use SHOW BACKUPS. If you are restoring an incremental backup, the URI must point to the storage location that contains the full backup:
Restore a cluster
To restore a full cluster:SHOW BACKUPS.
Restore a database
To restore a database:SHOW BACKUPS.
RESTORE DATABASE can only be used if the entire database was backed up.Restore a table
To restore a single table:SHOW BACKUPS.
Restore with AS OF SYSTEM TIME
RESTORE will only restore the latest data as per an AS OF SYSTEM TIME restore. The restore will not include historical data even if you ran your backup with revision_history.revision_history, it is still possible to use AS OF SYSTEM TIME with RESTORE to target a particular time for the restore. However, your restore will be limited to the times of the full backup and each incremental backup in the chain. In this case, use the following example to restore to a particular time.
First, find the times that are available for a point-in-time-restore by listing the available backup directories in your storage location:
start_time and end_time detail to define the required time as part of the AS OF SYSTEM TIME clause. Run the restore, passing the directory and the timestamp:
Restore a backup asynchronously
Use theDETACHED option to execute the restore asynchronously:
DETACHED option, RESTORE will block the SQL connection until the job completes. Once finished, the job status and more detailed job data is returned:
Other restore usages
Restore tables into a different database
By default, tables and views are restored to the database they originally belonged to. However, using theinto_db option, you can control the destination database. Note that the destination database must exist prior to the restore.
-
Create the new database that you’ll restore the table or view into:
-
Restore the table into the newly created database with
into_db:
Rename a database on restore
To rename a database on restore, use thenew_db_name option:
RESTORE with new_db_name, the existing database that was originally backed up can remain active:
Remove the foreign key before restore
By default, tables with constraints must be restored at the same time as the tables they reference. However, using the option you can remove the foreign key constraint from the table and then restore it.Restoring users from system.users backup
The system.users table stores your cluster’s usernames and their hashed passwords. To restore them, you must restore the system.users table into a new database because you cannot drop the existing system.users table.
After it’s restored into a new database, you can write the restored users table data to the cluster’s existing system.users table.
-
Create the new database that you’ll restore the
system.userstable into: -
Restore the
system.userstable into the new database: -
After the restore completes, add the
usersto the existingsystem.userstable: -
Remove the temporary
userstable:
Restore from incremental backups in a different location
Removed in v26.2: The
incremental_location option has been removed in v26.2, following its prior . Existing backups taken with this option cannot be restored in v26.2 or later. If you have backups that use incremental_location, you can only restore them using a cluster running v26.1 or earlier.RESTORE statement with both:
- the collection URI of the full backup
- the
incremental_locationoption referencing the incremental backup’s collection URI, as passed in the originalBACKUPstatement
BACKUP, see .
Known limitations
RESTOREwill not restore a table that references a , unless you skip restoring the function with theskip_missing_udfsoption. Alternatively, take a to include everything needed to restore the table.- Restoring and tables into a non-multi-region database is not supported.
- and tables can be restored only if the regions of the backed-up table match those of the destination database. All of the following must be true for
RESTOREto be successful:- The of the source database and the regions of the destination database have the same set of regions.
- The regions were added to each of the databases in the same order.
-
The databases have the same .
The following example would be considered as having mismatched regions because the database regions were not added in the same order and the primary regions do not match.
Running on the source database:
Running on the destination database:In addition, the following scenario has mismatched regions between the databases since the regions were not added to the database in the same order. Running on the source database:Running on the destination database:

