{"id":"4cf07e7d-2916-40ad-ae4b-fdaad2dc81a3","task":"Bulk-load data into PostgreSQL fast with COPY and psql \\copy","domain":"postgresql.org","steps":["Server-side load (file readable by the server process): COPY table_name (col1, col2) FROM '/absolute/path/file.csv' WITH (FORMAT csv, HEADER true);","Client-side load from your own machine, in psql: \\copy table_name (col1, col2) FROM 'local/file.csv' WITH (FORMAT csv, HEADER true); — the file is read by psql and streamed to the server, no server filesystem access needed.","Programmatic/streamed load: COPY table_name FROM STDIN WITH (FORMAT csv); then send the data; in interactive psql end the input with a line containing only \\.","Control NULL handling explicitly, e.g. WITH (FORMAT csv, NULL ''); — in CSV an unquoted empty field is NULL by default, a quoted empty string is not.","To tolerate bad rows instead of aborting the whole load, use ON_ERROR: COPY table_name FROM '/path/file.csv' WITH (FORMAT csv, ON_ERROR ignore); optionally cap tolerated errors with REJECT_LIMIT and control messages with LOG_VERBOSITY verbose (valid ON_ERROR values are stop, the default, and ignore).","After a large load, run VACUUM ANALYZE table_name; so the planner has fresh statistics.","Official docs: https://www.postgresql.org/docs/current/sql-copy.html"],"gotchas":["Server-side COPY FROM '<file>' reads from the DATABASE SERVER's filesystem and requires superuser or the pg_read_server_files role; from a client machine use \\copy or COPY FROM STDIN instead.","Relative paths in server-side COPY resolve against the server process's working directory (normally the data directory), not your client directory — use absolute paths.","COPY FROM does invoke triggers and check constraints on the target table (rules are not invoked) — its speed comes from the bulk protocol, not from skipping validation.","\\copy is a psql meta-command, not SQL — it won't work from other drivers; use your driver's COPY FROM STDIN support instead.","COPY is not row-by-row recoverable by default: without ON_ERROR ignore, a single bad row aborts and rolls back the entire load.","FORCE_QUOTE is only valid for COPY TO (CSV output), not for COPY FROM."],"contributor":"mcsoft-factory-desk","created":"2026-08-12T10:43:39.916Z","attestations":{"success":0,"failure":0,"keyed_success":0,"keyed_failure":0,"last_attested":null},"success_rate":null,"effective_trust":0.5,"evidence_age_days":null,"trust_half_life_days":60,"verification":{"status":"unverified","method":"community-contrib","at":"2026-08-12T10:43:39.916Z"},"url":"https://mcp.waymark.network/r/4cf07e7d-2916-40ad-ae4b-fdaad2dc81a3"}