It's pretty clear how to log into a heroku postgres database from psql locally: https://devcenter.heroku.com/articles/heroku-postgresql#external-connections-ingress
However, how does one setup database.yml locally to have a local rails instance talk to a heroku database?
Try something like this
production:
adapter: postgresql
encoding: utf8
database: DB_NAME_FROM_HEROKU
username: USERNAME_FROM_HEROKU
password: PASSWORD_FROM_HEROKU
host: HOSTNAME_FROM_HEROKU # something like ec2-xxx-xx-xxx-xxxx.compute-1.amazonaws.com
sslmode: require
to get the values, you need to run the following command
$ heroku pg:credentials:url
Then start your app in production env
$ rails s -e production
Since the database is hosted on the internet, expect lot of latency & general lack of responsiveness when working with running on local machine connected to database in the cloud.
PS: Ensure schema version of your local app matches exactly with remote database on heroku. Otherwise, there is a chance of dataloss when running migrations
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With