Runbook — Restore a Postgres database from pg_dump¶
Use when: a single DB has corrupted data, a bad migration shipped, or a destructive query ran in prod.
Prerequisites¶
- SSH access to the VPS (
ssh vps) - Knowledge of which DB to restore (e.g.
jb_brain) - A backup file in
/opt/backups/postgres/<db>_<date>.sql.gz
Steps¶
-
Identify the target dump
Pick the most recent dump before the bad event. -
Stop the app(s) writing to the DB
-
Snapshot the current (bad) state first — never delete what you cannot get back
-
Drop and recreate the DB
-
Restore from the dump
-
Verify
-
Start the apps back up
-
Confirm app healthchecks pass before considering the incident resolved.
Rollback¶
If the restore made things worse:
docker exec infra-postgres psql -U postgres -c "DROP DATABASE <db_name>;"
docker exec infra-postgres psql -U postgres -c "CREATE DATABASE <db_name> OWNER <db_owner>;"
gunzip -c /opt/backups/postgres/<db_name>_predeath_*.sql.gz | \
docker exec -i infra-postgres psql -U postgres <db_name>
Post-mortem¶
Write the incident up in runbooks/post-mortems/ within 24h.