To put files on your CockroachDB cluster without external servers, use userfile
, a per-user bulk file storage. To interact with userfile
, use the following commands:
Once a userfile is uploaded, you can run IMPORT
.
New in v21.1: For PGDUMP
and MYSQLDUMP
formats, you can use cockroach import
to upload a userfile, import its data, and delete the userfile in one command.
Upload a file
A userfile uses storage space in the cluster, and is replicated with the rest of the cluster's data. We recommend using cockroach userfile upload
for quick uploads from your client (about 15MB or smaller).
$ cockroach userfile upload /Users/maxroach/Desktop/test-data.csv /test-data.csv --certs-dir=certs
successfully uploaded to userfile://defaultdb.public.userfiles_root/test-data.csv
For more information, see cockroach userfile upload
.
List files
$ cockroach userfile list '*.csv' --certs-dir=certs
userfile://defaultdb.public.userfiles_root/test-data-2.csv
userfile://defaultdb.public.userfiles_root/test-data.csv
For more information, see cockroach userfile list
.
Get files
$ cockroach userfile get test-data.csv --certs-dir=certs
For more information, see cockroach userfile get
.
Delete files
$ cockroach userfile delete test-data.csv --certs-dir=certs
deleted userfile://defaultdb.public.userfiles_root/test-data.csv
For more information, see cockroach userfile delete
.
Upload and import from a dump file
We recommend using cockroach import
for quick imports from your client (about 15MB or smaller). For larger imports, use the IMPORT statement.
$ cockroach import db mysqldump /Users/maxroach/Desktop/test-db.sql --certs-dir=certs
successfully imported mysqldump file /Users/maxroach/Desktop/test-db.sql
For more information, see cockroach import
.
Import from userfile
> IMPORT TABLE customers (
id INT,
dob DATE,
first_name STRING,
last_name STRING,
joined DATE
)
CSV DATA (
'userfile:///test-data.csv'
);
userfile:///
references the default path (userfile://defaultdb.public.userfiles_$user/
).
job_id | status | fraction_completed | rows | index_entries | bytes
---------------------+-----------+--------------------+--------+---------------+-----------
599865027685613569 | succeeded | 1 | 300024 | 0 | 13389972
(1 row)
For more import options, see IMPORT
or IMPORT INTO
.