Heroku: How to sync your production database with your development environment.

Apart from heroku db:pull (uses taps and imports from psql to any local sql database) there is a faster way to download and import the production data to your local server.

1. Generate a dump file of the production database using

heroku pgbackups:capture

This will actually run the pg_dump script on the production server
2. List the backups

heroku pagbackups

3. Get the download-able url of the latest backup listed

heroku pgbackups {lates_backup_name}:url

4. Download the file using the returned url.

Postgresql can use the files comming from the pg_dump with the usage of pg_restore.

Now try this

pg_restore --verbose --clean --no-acl --no-owner -h -U savvasmsc -d sweetlifer_development ~/Downloads/b019.dump
  • Gingernille

    I think Heroku changed the syntax for #3. Also incude a flag for the specific app if you have multiple apps.

    heroku pgbackups:url {LAST_BACKUP_ID} –app {APP_NAME_HERE}

    • david rawk

      This does not get all schemas.. I’m not sure why, but my public schema was skipped in the dump.

  • Chris Tinderfields

    Sorry I found a typo: “pagbackups”. Thanks for the article.