Importing Heroku PostgreSQL to localhost

Importing a Heroku PostgreSQL database to your local machine, quickly and easily.

Posted by Curtis Miller Curtis Miller

It can sometimes be useful to operate against a more robust set of data on your local machine, especially when you're seeing different behavior locally vs on staging/production. If you're using Heroku with PostgreSQL, this can be very easy with the right set of commands.

From the root directory of your project request that a new backup be created on Heroku.

  heroku pg:backups:capture

NOTE: If you have more than one Heroku app available, then you'll need to specify which one by using the `-a APP` or `-r REMOTE` options.

You should now have a backup available to you, which you'll want to download to your local machine. Heroku also offers a command to help with grabbing the latest backup. Again, you may need to specify the app or remote here.

  heroku pg:backups:download

Finally, you can restore this backup (latest.dump) to your local PostgreSQL database. This will overwrite the database specified, so be cautious.

  pg_restore --verbose --clean --no-acl --no-owner -h localhost -d [DATABASE NAME] latest.dump

Happy debugging!



Velocity Labs

Need web application development, maintenance for your existing app, or a third party code review?

Velocity Labs can help.

Hire us!