21 lines
647 B
Markdown
21 lines
647 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 > /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 < /tmp/dump.sql
|
|
``` |