Restore a Postgres Database from Your VPS to Heroku



If your fledgling app isn’t gaining much traction and you don’t want to pay monthly fees for hosting a vps and you don’t want to see all the hours you pured into your app to disappear, why not move it over to heroku for free?

One caviet from using pg_dump that heroku doesn’t tell you is that heroku uses the custom format so if you try to import a regular dump in plain text format, the restore process in heroku will fail.

So do the following:

move to a public directory on yout server and dump your database

pg_dump -h localhost -U postgres production_db_name -F c -f name_of_backup.dump

move into your local folder where you have already added you heroku keys and run the restore

heroku pg:backups restore 'http://my_domain/public_folder/name_of_backup.dump' DATABASE_URL

And you’re done!