Cockroach Labs recommends using because they provide better performance for growing workloads. Additionally, changefeeds operate as jobs, which offer , , and .
EXPORT exports tabular data or the results of arbitrary SELECT statements to the following:
- CSV files
- Parquet files
EXPORT parallelizes file creation across all nodes in the cluster, making it possible to quickly get large sets of data out of CockroachDB in a format that can be ingested by downstream systems.
If you do not need distributed exports, you can export tabular data in CSV format.
Cancelling export
After the export has been initiated, you can cancel it with . For detail on handling partially complete exports at the destination, refer to Export File URL.Synopsis
The
EXPORT statement cannot be used within a .Required privileges
The user must have theSELECT on the table being exported, unless the .
Destination 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:
- Interacting with a cloud storage resource using .
- Using a custom endpoint on S3.
- Using the command.
- Using or HTTPS.
- 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 S3-compatible services (e.g., MinIO, Red Hat Ceph).
Parameters
Export file URL
You can specify the base directory where you want to store the exported files. CockroachDB will create the export file(s) in the specified directory with programmatically generated names (e.g.,exportabc123-n1.1.csv, exportabc123-n1.2.csv, exportabc123-n2.1.csv, …). Each export should use a unique destination directory to avoid collision with other exports.
The EXPORT command returns the list of files to which the data was exported. You may wish to record these for use in subsequent imports.
If an export encounters some kind of failure or cancellation, it will leave any written files behind in the destination. To run a new export and avoid collision with previously written export files, consider doing the following:
- Change the destination (or destination prefix) that you are exporting to.
- Remove the partial results at the destination from any previously attempted exports.
- Use a instead because it operates as a job, offering more observability into failures.
A hexadecimal hash code (
abc123... in the file names) uniquely identifies each export run; files sharing the same hash are part of the same export. If you see multiple hash codes within a single destination directory, then the directory contains multiple exports, which will likely cause confusion (duplication) on import. We recommend that you manually clean up the directory, to ensure that it contains only a single export run.Export options
You can control the process’s behavior using any of the following key-value pairs as akv_option.
Success responses
SuccessfulEXPORT returns a table of (perhaps multiple) files to which the data was exported:
Parquet types
CockroachDB types map to Parquet types listed in the following table. All columns witten to Parquet files will be nullable, therefore the Parquet repetition level isoptional.
Exports and AS OF SYSTEM TIME
The clause is not required in EXPORT statements, even though they are long-running queries. If it is omitted, AS OF SYSTEM TIME is implicitly set to the start of the statement’s execution. The risk of is low because other transactions would need to have exactly the same transaction start time as the EXPORT statement’s start time.
Examples
The following examples make use of:- Amazon S3 connection strings. For guidance on connecting to other storage options or using other authentication parameters instead, read .
- The default
AUTH=specifiedparameter. For guidance on usingAUTH=implicitauthentication with Amazon S3 buckets instead, read .
- External connections, which allow you to represent an external storage or sink URI. You can then specify the external connection’s name in statements rather than the provider-specific URI. For detail on using external connections, see the page.
- Assume role authentication, which allows you to limit the control specific users have over your storage buckets. See for more information.
bank database and the customers table; customer-export-data is the demonstration path to which we’re exporting our customers’ data in this example.
Export a table into CSV
This example uses thedelimiter option to define the ASCII character that delimits columns in your rows:
nullas option to define the string that represents NULL values:
Export a table into Parquet
Export using a SELECT statement
Non-distributed export using the SQL client
Export compressed files
gzip compression is supported for both PARQUET and CSV file formats:
PARQUET data also supports snappy compression:
Export tabular data with an S3 storage class
To associate your export objects with a in your Amazon S3 bucket, use theS3_STORAGE_CLASS parameter with the class. For example, the following S3 connection URI specifies the INTELLIGENT_TIERING storage class:
Export data out of CockroachDB Cloud
UsingEXPORT with is not recommended. You can either export data to or to a local CSV file by using :
- local CSV
- Cloud storage
The following example exports the
customers table from the bank database into a local CSV file:View a running export
View running exports by using :Cancel a running export
Use to get a running export’squery_id, which can be used to :
Known limitation
EXPORT may fail with an error if the SQL statements are incompatible with DistSQL. In that case, export tabular data in CSV format.

