COPY moves data between a PostgreSQL table and a file or query, enabling quick table transfers across databases.
Moving a single table to another database is common when separating tenants, archiving data, or migrating workloads without moving the whole cluster.
Use the built-in COPY
command to export the source table to a file, then run COPY
again in the target database to import.This approach avoids extra extensions and leverages PostgreSQL’s high-throughput bulk I/O.
Connect to the source ParadeDB database and stream the table to a compressed file:
\! gzip -c <(\copy Customers TO STDOUT (FORMAT csv, HEADER, DELIMITER ',')) > customers.csv.gz
Move customers.csv.gz
to the destination server with scp
, cloud storage, or a shared volume.
Run the DDL that matches the source schema:
CREATE TABLE Customers (id INT, name TEXT, email TEXT, created_at TIMESTAMPTZ);
Decompress and load in one step:
gunzip -c customers.csv.gz | psql -d target_db -c "\copy Customers FROM STDIN WITH (FORMAT csv, HEADER, DELIMITER ',')"
Yes.Use dblink
or postgres_fdw
to stream rows directly with INSERT INTO ... SELECT
.This eliminates disk I/O at the cost of some setup.
CREATE EXTENSION IF NOT EXISTS postgres_fdw;
CREATE SERVER src_db FOREIGN DATA WRAPPER postgres_fdw OPTIONS (host 'src', dbname 'paradedb');
CREATE USER MAPPING FOR CURRENT_USER SERVER src_db OPTIONS (user 'app', password 'secret');
IMPORT FOREIGN SCHEMA public LIMIT TO (Customers) FROM SERVER src_db INTO public;
INSERT INTO Customers SELECT * FROM Customers_foreign;
COPY
is fastest for large tables (>1 GB) because it bypasses row-level overhead.postgres_fdw
is convenient for frequent, smaller transfers or when you need WHERE filtering during the copy.
1. Disable indexes and constraints on the target until after the import.
2. Use FORMAT binary
for even faster loads when both databases have identical versions.
3.Wrap steps in a transaction to keep the target consistent.
Wrong delimiter in CSV. Always specify DELIMITER
to match the export.
Timestamp mismatch. Use TIMESTAMPTZ
to avoid timezone drift.
Galaxy’s desktop SQL editor lets you run COPY
with templates and AI-generated scripts for one-click table transfers between ParadeDB databases.
.
COPY
runs on the server; \copy
is a psql wrapper that streams data through the client. Use \copy
when the server lacks filesystem access.
Yes. Create a temp table or use COPY (SELECT ... WHERE ...)
TO STDOUT to export a subset.
It takes a SHARE ROW EXCLUSIVE lock, allowing SELECTs but blocking concurrent writes. Plan exports during off-peak hours.