How to import a Heroku PG dump into local machine
You see errors because psql tries to interpret SQL queries when you're actually giving him a compressed dump (that's what heroku uses).
While you can't read the dump, pg_restore -O latest.dump
gives you valid SQL you could pipe to psql but the easy solution is the following one :
pg_restore -O -d app_development latest.dump
Notes :
- Use
-O
because you probably don't use the random username of your remote heroku postgres db. - Heroku doesn't recommend to use taps but I don't know how really risky it is.
Use the Taps gem. It allows you to run a simple heroku db:pull
to populate a local database.
Follow these 4 simple steps in your terminal
(Heroku Dev Center):
Create a backup copy of your database:
$ heroku pg:backups capture DATABASE_NAME
Download the copy from Heroku (to your local machine) using curl:
$ curl -o latest.dump `heroku pg:backups public-url`
Load it*:
$ pg_restore --verbose --clean --no-acl --no-owner -h localhost -U YOUR_USERNAME -d DATABASE_NAME latest.dump
- get YOUR_USERNAME and choose the desired database from your
config/database.yml
file. - DATABASE_NAME can be your development/test/production db (Ex. mydb_development)
- get YOUR_USERNAME and choose the desired database from your
That's it!