# Importing Heroku PostgreSQL to localhost

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

- Author: Curtis Miller
- Published: 2019-07-03
- Categories: ops, rails, how-to
- Canonical URL: https://millarian.com/posts/importing-heroku-postgresql-to-localhost/

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.

```shell
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.

```shell
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.

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

Happy debugging!
