IMPORT INTO is the fastest method to ingest data into CockroachDB but it requires taking the target table offline for the duration of the import. IMPORT INTO is a good choice for initial data migrations and data migrations that can tolerate table downtime. If you cannot tolerate table unavailability, we recommend using instead.
Import performance primarily depends on the amount of data that you want to import. However, there are three actions you should take before importing that have a significant impact on the amount of time it takes to run an import:
If the import size is less than 100 GiB, then you do not need to do anything to optimize performance. For such small datasets, the import should run quickly, regardless of the settings.
Choose a performant import format
Different import file formats do not have the same performance due to the way they are processed by CockroachDB. The fastest import file formats are:- or (both have about the same import performance).
- .
CSV or AVRO. These formats can be processed in parallel by all the nodes in the cluster, which increases performance. To import in these formats, use .
Import the schema separately from the data
When importing into a new table, split your dump data into two files:- A SQL file containing the table schema.
- A CSV, delimited, or AVRO file containing the table data.
Import into a schema with secondary indexes
When importing data into a table with , the import job will ingest the table data and required secondary index data concurrently. This may result in a longer import time compared to a table without secondary indexes. However, this typically adds less time to the initial import than following it with a separate pass to add the indexes. As a result, importing tables with their secondary indexes is the default workflow, an effective strategy for most migrations. However, in large imports (that is, datasets larger than 100 GiB in total size), it may be preferable to temporarily from the schema, , and then . Write operations on tables with many secondary indexes take longer to complete, and importing large datasets have a greater risk of timeouts. Removing the table’s secondary indexes allows you to separate the initial data import from the secondary index creation operation, and the total import time is lower. Separating these operations also provides increased visibility into each operation’s progress, and the ability to retry each operation independently if you encounter errors or timeouts. When recreating the secondary indexes, execute the statements one at a time for best performance. For example:Temporarily remove foreign keys
When importing data into a table with , temporarily remove the foreign keys, and add them after the initial migration with an .Data type sizes
Above a certain size, many data types such as s, s, , , and may run into performance issues due to . See each data type’s documentation for its recommended size limits.Split your data into multiple files
Splitting the import data into multiple files can have a significant impact on the import performance. The following formats support multi-file import usingIMPORT INTO:
CSVDELIMITED DATAAVRO
You can split the data into more files than you have nodes. CockroachDB will process the files in parallel across the cluster. When splitting the data Cockroach Labs recommends splitting it into a multiple of the number of nodes in your cluster, if possible. For example, if you have a 3 node cluster, split the dataset into 9, 27, or 300 files.Cockroach Labs recommends keeping the files to a maximum file size of 4 GB unless the files are streamed (for example, will stream the data to CockroachDB), and to keep each file size similar across the dataset. For example, if you are importing a 9 GB dataset that was split into 3 files into a 3 node cluster, keep each file around 3 GB in size if possible. Don’t split the data into two 4 GB files, and one 1 GB file.

