Verifying a Postgres dump by restoring it into a scratch database
Restore each dump into a throwaway database and compare table counts.
What it’s for
Section titled “What it’s for”Catching empty or broken Postgres dumps before you need them.
What you need
Section titled “What you need”kubectl execaccess to the Postgres pod
- Dump in custom format:
kubectl exec -n <ns> <pg-pod> -- pg_dump -Fc -U <user> -d <db> > db.dump- Make a scratch database:
S=restore_verify_$(date +%s)kubectl exec -n <ns> <pg-pod> -- createdb -U <user> $S- Restore into it:
kubectl exec -i -n <ns> <pg-pod> -- \ pg_restore --no-owner --no-privileges -U <user> -d $S < db.dump- Count public tables in both:
Q="SELECT count(*) FROM information_schema.tables WHERE table_schema='public';"kubectl exec -n <ns> <pg-pod> -- psql -U <user> -d <db> -tAc "$Q"kubectl exec -n <ns> <pg-pod> -- psql -U <user> -d $S -tAc "$Q"- Drop the scratch database:
kubectl exec -n <ns> <pg-pod> -- dropdb -U <user> $SCheck it worked
Section titled “Check it worked”The two counts match. Counts seen in this homelab: Infisical 752, Gitea 116, LiteLLM 91, Kaneo 45, Hindsight 24.
Traps seen
Section titled “Traps seen”- Don’t assume table names. Infisical renames
knex_migrationstoinfisical_migrations. - For a migration, compare row counts on the important tables too.
Where this came from
Section titled “Where this came from”- Test-restoring each Postgres dump into a scratch database (2026-10-17)
- Moving LiteLLM and its database to K3s (2026-10-21)