Populate a postgreSQL database on Heroku
Learn how to populate a remote postgreSQL database on Heroku from an existing database dump.
We recommend adding on your Heroku application the free add-on “Heroku Postgres” (1)(2).
Once installed, your Heroku application will contain an environment variable
DATABASE_URLwith the credentials of your new created database (1) in the “Config Vars” section (2). Here you can add more if necessary (3).
Your new database has no data yet, so you will need to import your local data to this new one.
To do that, you first need to create a dump of your local database.
PGPASSWORD=secret pg_dump -h localhost -p 5416 -U forest forest_demo --no-owner --no-acl -f database.dump
Then, you need to import it to the Heroku database.
heroku pg:psql DATABASE_URL --app name_of_your_app < database.dump
At this stage, your Heroku application is entirely running with its own database.
That's it! Your local database is now available as your production database on Heroku. 🎉
N.B: You can make sure by checking the Heroku logs using the command :
heroku logs -t -a name_of_your_app