Skip to content

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

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

Restoring a Database

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