Files
code-snippets/docs/postgres/dump-and-restore.md
Liam Pietralla 32f943ac34
All checks were successful
Build, Test & Publish / Build (pull_request) Successful in 27s
Build, Test & Publish / Build and Publish Container Image (pull_request) Has been skipped
Build, Test & Publish / Deploy to Infrastructure (pull_request) Has been skipped
fix
2025-10-15 16:14:10 +11:00

21 lines
649 B
Markdown

# 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
```