cockroach import

On this page Carat arrow pointing down
Warning:
CockroachDB v21.1 is no longer supported. For more details, see the Release Support Policy.

New in v21.1: The cockroach import command imports a database or table from a local dump file into a running cluster. This command uploads a userfile, imports its data, then deletes the userfile. PGDUMP and MYSQLDUMP file formats are currently supported.

Note:

We recommend using cockroach import for quick imports from your client (about 15MB or smaller). For larger imports, use the IMPORT statement.

Required privileges

The user must have CREATE privileges on defaultdb.

Synopsis

Import a database:

$ cockroach import db <format> <location/of/file> <flags>

Import a table:

$ cockroach import table <table_name> <format> <location/of/file> <flags>

View help:

$ cockroach import --help

Supported Formats

Flags

Flag Description
--certs-dir The path to the certificate directory containing the CA and client certificates and client key.

Env Variable: COCKROACH_CERTS_DIR
Default: ${HOME}/.cockroach-certs/
--insecure Use an insecure connection.

Env Variable: COCKROACH_INSECURE
Default: false
--user
-u
The SQL user that will own the client session.

Env Variable: COCKROACH_USER
Default: root
--ignore-unsupported-statements New in v21.1: Ignore statements that are unsupported during an import from a PGDUMP file.
Default: false
--log-ignored-statements New in v21.1: Log statements that are ignored during an import from a PGDUMP file to the specified destination (i.e., cloud storage or userfile storage.
--row-limit= New in v21.1: The number of rows to import for each table during a PGDUMP or MYSQLDUMP import.
This can be used to check schema and data correctness without running the entire import.
Default: 0

Examples

Import a database

To import a database from a local file:

icon/buttons/copy
$ cockroach import db mysqldump /Users/maxroach/Desktop/test-db.sql --certs-dir=certs
successfully imported mysqldump file /Users/maxroach/Desktop/test-db.sql

Import a table

To import a table from a local file:

icon/buttons/copy
$ cockroach import table test_table pgdump /Users/maxroach/Desktop/test-db.sql --certs-dir=certs
successfully imported table test_table from pgdump file /Users/maxroach/Desktop/test-db.sql

Import a database with unsupported SQL syntax and log all unsupported statements

New in v21.1: To import a database from a PGDUMP file that contains unsupported SQL syntax and log the ignored statements to a userfile:

icon/buttons/copy
$ cockroach import db pgdump /Users/maxroach/Desktop/test-db.sql --certs-dir=certs --ignore-unsupported-statements=true --log-ignored-statements='userfile://defaultdb.public.userfiles_root/unsupported-statements.log'
successfully imported table test_table from pgdump file /Users/maxroach/Desktop/test-db.sql

Import a limited number of rows from a dump file

New in v21.1: To limit the number of rows imported from a dump file:

icon/buttons/copy
$ cockroach import table test_table pgdump /Users/maxroach/Desktop/test-db.sql --certs-dir=certs --row-limit='50'
successfully imported table test_table from pgdump file /Users/maxroach/Desktop/test-db.sql

See also


Yes No
On this page

Yes No