Title: Postgres Export to CSV and pg_dump (Visually or in SQL)
Open Graph Title: Postgres Export to CSV and pg_dump (Visually or in SQL)
X Title: Postgres Export to CSV and pg_dump (Visually or in SQL)
Description: Postgres export to CSV or JSON in a few clicks, or a whole database to SQL. Or use COPY, \copy and pg_dump for query results, Excel and full backups.
Open Graph Description: Postgres export to CSV or JSON in a few clicks, or a whole database to SQL. Or use COPY, \copy and pg_dump for query results, Excel and full backups.
X Description: Postgres export to CSV or JSON in a few clicks, or a whole database to SQL. Or use COPY, \copy and pg_dump for query results, Excel and full backups.
Opengraph URL: https://1bench.dev/tutorials/postgresql/export-data
Domain: 1bench.dev
IPv4 address: 172.67.136.224
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://1bench.dev"},{"@type":"ListItem","position":2,"name":"Tutorials","item":"https://1bench.dev/tutorials"},{"@type":"ListItem","position":3,"name":"PostgreSQL","item":"https://1bench.dev/postgresql"},{"@type":"ListItem","position":4,"name":"PostgreSQL Export to CSV, JSON, Excel and SQL Dumps","item":"https://1bench.dev/tutorials/postgresql/export-data"}]}
{"@context":"https://schema.org","@type":"Article","headline":"Postgres Export to CSV and pg_dump (Visually or in SQL)","description":"Postgres export to CSV or JSON in a few clicks, or a whole database to SQL. Or use COPY, \\copy and pg_dump for query results, Excel and full backups.","url":"https://1bench.dev/tutorials/postgresql/export-data","dateModified":"2026-11-02","datePublished":"2026-11-02","image":"https://1bench.dev/api/og?title=PostgreSQL+Export+to+CSV%2C+JSON%2C+Excel+and+SQL+Dumps&v=2&eyebrow=PostgreSQL+%C2%B7+Tutorial&subtitle=Step+by+step%2C+in+SQL+and+in+1bench&tag=1bench.dev%2Ftutorials%2Fpostgresql%2Fexport-data","author":{"@type":"Organization","name":"1bench","url":"https://1bench.dev","logo":"https://1bench.dev/icon.png"},"publisher":{"@type":"Organization","name":"1bench","url":"https://1bench.dev","logo":"https://1bench.dev/icon.png"},"mainEntityOfPage":{"@type":"WebPage","@id":"https://1bench.dev/tutorials/postgresql/export-data"}}
{"@context":"https://schema.org","@type":"FAQPage","mainEntity":[{"@type":"Question","name":"Should I use pg_dump or COPY to export a PostgreSQL table?","acceptedAnswer":{"@type":"Answer","text":"Use COPY or \\copy when you want the rows in a file another tool reads, such as CSV for a spreadsheet or a data pipeline. Use pg_dump when the file goes back into PostgreSQL, since it carries the CREATE TABLE, indexes, constraints and sequence values along with the data. pg_dump -t orders --data-only sits between the two: rows only, but in a form psql can load."}},{"@type":"Question","name":"Is pg_dump safe to run on a live database?","acceptedAnswer":{"@type":"Answer","text":"Yes. pg_dump reads from one snapshot and takes only ACCESS SHARE locks (its LOCK TABLE ... IN ACCESS SHARE MODE shows up in error output), so reads and writes carry on while it runs. What it does block is DDL: an ALTER TABLE or DROP TABLE on a dumped table waits until the dump finishes. On a busy server, run it against a replica or off-peak."}},{"@type":"Question","name":"How do I export all tables in a PostgreSQL database to CSV?","acceptedAnswer":{"@type":"Answer","text":"There is no single command for it, so loop over pg_tables in the shell: for t in $(psql -d saas_app -Atc \"SELECT tablename FROM pg_tables WHERE schemaname = 'public'\"); do psql -d saas_app -c \"\\copy public.$t TO '$t.csv' WITH (FORMAT csv, HEADER)\"; done. Each table lands in its own file named after it. Each \\copy runs in its own session, so the files are not one consistent snapshot; use pg_dump if that matters."}},{"@type":"Question","name":"Can pg_dump export only rows that match a WHERE clause?","acceptedAnswer":{"@type":"Answer","text":"No. pg_dump has no row filter, and pg_dump --where fails with \"unrecognized option '--where'\". Export the rows with \\copy (SELECT * FROM orders WHERE status = 'shipped') TO 'shipped.csv' CSV HEADER, or copy them into a scratch table with CREATE TABLE ... AS SELECT and dump that table with -t."}},{"@type":"Question","name":"What is the difference between pg_dump and pg_basebackup?","acceptedAnswer":{"@type":"Answer","text":"pg_dump is a logical backup: SQL or an archive of one database that restores into any newer PostgreSQL version and lets you pick tables. pg_basebackup copies the whole cluster's data files byte for byte, so it restores only into the same major version, but together with WAL archiving it supports point-in-time recovery. Most teams keep both for different jobs."}}]}
| og:site_name | 1bench |
| og:image | https://1bench.dev/api/og?title=PostgreSQL+Export+to+CSV,+JSON,+Excel+and+SQL+Dumps&v=2&eyebrow=PostgreSQL+·+Tutorial&subtitle=Step+by+step,+in+SQL+and+in+1bench&tag=1bench.dev/tutorials/postgresql/export-data |
| og:image:width | 1200 |
| og:image:height | 630 |
| og:type | article |
| article:published_time | 2026-11-02 |
| article:modified_time | 2026-11-02 |
| twitter:card | summary_large_image |
| twitter:image | https://1bench.dev/api/og?title=PostgreSQL+Export+to+CSV,+JSON,+Excel+and+SQL+Dumps&v=2&eyebrow=PostgreSQL+·+Tutorial&subtitle=Step+by+step,+in+SQL+and+in+1bench&tag=1bench.dev/tutorials/postgresql/export-data |
Links:
| Server | cloudflare |
| Content-Type | text/html; charset=utf-8 |
| X-Powered-By | Next.js |
| Via | 1.1 Caddy |
| Cache-Control | public, s-maxage=86400, stale-while-revalidate=604800 |
Viewport: width=device-width, initial-scale=1