Syncing a Postgres Database from Heroku to Local

Capture

Capture a new backup if you want.

1heroku pg:backups capture

Download a dump of the database from a temporary, public URL.

1curl -o database.dump `heroku pg:backups public-url`

Import

Create a new database if necessary.

1create_db my_database

Import the database dump.

1pg_restore -h localhost -d my_database database.dump

Some flags for pg_restore:

  • --clean, -c: drop database objects before recreating.
  • --no-acl, -x: don't restore access privileges.
  • --no-owner, -O: don't restore ownership.
  • --verbose, -v: verbose, if you want to see the details.

See the PostgreSQL documentation for more.