Search code examples
ruby-on-railsrubypostgresqlherokupg

Working on a rails app locally with a remote Postgres connection?


Is there a way to configure the database.yml file to connect to Heroku's Postgres remotely?

I'm having trouble understanding how Heroku, Rails and PG gem work together.

It looks like during deployment, Heroku re-writes the database.yml file - is it possible to see the contents of this updated .yml file and use it locally?


Solution

  • Below are the steps to access Heroku db from local development:

    1. Login to your heroku account.

    2. Navigate to this URL https://postgres.heroku.com/databases/ OR you can get heroku db url by running this command in the terminal: heroku pg:credentials:url

    3. Select your application database.

    4. You will able to see your heroku pg credentials:

      Host         xxxxxxxxx.77777.amazonaws.com
      Database     42feddfddeee 
      Username         44444444444
      Port         xxxx
      Password     777sfsadferwefsdferwefsdf
      
    5. collect above details and put in your databse.yml file development evn:

      adapter: postgresql  
      host: < host >                            # HOST 
      port: < port >                            # Port  
      database: < database name >               # Database Name  
      username: < user_name >                   # User Name  
      password: '< password >'                  # Password 
      

    Restart you application,

    Best of luck..!!