Files
code-snippets/docs/postgres/dump-and-restore.md
2025-10-15 13:16:21 +11:00

647 B

Dump and Restore

Handy commands for dumping and restoring Postgres databases.

:::info Most of these commands are run using Docker as then we don't need to have Postgres installed locally.

If a different version of Postgres is needed, just change the version number in the Docker image tag. :::

Dumping a Database

docker run --network host --rm -v .:/tmp -e PGPASSWORD=mysecretpassword postgres:16 pg_dump -h localhost -U myuser -d mydb > /tmp/dump.sql

Restoring a Database

docker run --network host --rm -v .:/tmp -e PGPASSWORD=mysecretpassword postgres:16 psql -h localhost -U myuser -d mydb < /tmp/dump.sql