Reputation: 1976
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
Upvotes: 2
Views: 966
Reputation: 3298
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
andENV['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.
Upvotes: 2