pg_dump mydb > mydb.sql

Category: Databases & SQL

pg_dump mydb > mydb.sql

Back up a database as plain SQL

Writes CREATE TABLE and INSERT statements for mydb to stdout; redirect into a file to keep it. Restore with psql -f mydb.sql or psql mydb < mydb.sql. Plain format is editable but slow to restore on large databases. Related: pg_dump -Fc for a compressed archive.
Looking for more? Search all 7,657 commands — works offline, in English or Spanish, and fixes typos.