Copying and populating a table from a local machine
Written by
Updated at December 25, 2025
Using the interactive psql
Getting started
-
Install the dependencies:
sudo apt update && sudo apt install --yes postgresql-client
Copying data from a table
To export table data to a file, run this command:
psql "host=c-<cluster_ID>.rw.mdb.yandexcloud.net \
port=6432 \
sslmode=verify-full \
dbname=<DB_name> \
user=<username> \
target_session_attrs=read-write" \
-c "\copy (SELECT * FROM <table_name>) to stdout (DELIMITER '<delimiter_character>')" \
>> <local_file_name>
Populating a table with data
Note
Make sure to create the target table beforehand. The local file’s column structure, i.e., number and data types, must match the Managed Service for PostgreSQL table schema.
To import data from a local file into a table, run this command:
cat <local_file_name> | \
psql "host=c-<cluster_ID>.rw.mdb.yandexcloud.net \
port=6432 \
sslmode=verify-full \
dbname=<DB_name> \
user=<username> \
target_session_attrs=read-write" \
-c "COPY <table_name> FROM stdin (DELIMITER '<delimiter_character>')"