2

I have an existing Rails app which was previously running successfully on my local laptop (running OSX) with the database stored locally in PostgreSQL. I've also successfully deployed the Rails app to Elastic Beanstalk with the database in RDS - the hosted site is still running.

I haven't touched the localhost version for months and tried to start it today using rails server -e development, but when visiting http://localhost:3000/ as per usual, I get a PG error message

PG::ConnectionBad at / FATAL: password authentication failed for user "murjfphxxxxxx" FATAL: no pg_hba.conf entry for host "115.x.x.x", user "murjfphxxxxxx", database "d37vsvehxxxxxx", SSL off

The same error is thrown in the Rails console. It seems that the development version is trying to connect to the AWS database, rather than the localhost database, but I can't figure out why.

/config/database.yml lists the development environment as:

development: adapter: postgresql encoding: unicode database: <my-app>_development host: localhost pool: 5 username: postgres password: <password>

I can connect to the localhost PG database via PSQL and see the contents, so it appears that the localhost PG database is valid.

Why would the development environment try to connect to the AWS version of the database? Please let me know if you need any further information to debug this.

Using ruby-2.3.1, Rails 4.2.0, PostgreSQL 9.6.0.0

4
  • Have you tried running rails s RAILS_ENV=development just to see if its using the proper environment? Commented Feb 13, 2017 at 11:18
  • @Coolness sorry I meant to mention that I had already tried that - I've edited the question. It made no difference to the result Commented Feb 13, 2017 at 11:19
  • 2
    do you have DATABASE_URL var in your env? (you can check by typing env | grep DATABASE_URL in terminal) Commented Feb 13, 2017 at 11:56
  • @esse bingo! Do you want to put that as an answer, and I'll accept it. Many thanks Commented Feb 13, 2017 at 20:33

1 Answer 1

2

You probably have DATABASE_URL in your env. You can check by typing env | grep DATABASE_URL in terminal.

If so, try unsetting it with unset DATABASE_URL.

As said in documentation:

If you have both config/database.yml and ENV['DATABASE_URL'] set then Rails will merge the configuration together. To better understand this we must see some examples.

When duplicate connection information is provided the environment variable will take precedence.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.