Reputation: 244
When I try to connect to my pg database using User.connection or generic-table.connection I get this error
PG::ConnectionBad: FATAL: Peer authentication failed for user 'username'
I double checked my database.yml and it looks good. I think the problem lies with my pg_bha.conf file? I can not find this file in my app or my system right now.
database.yml
development:
adapter: postgresql
encoding: utf8
database: project_development
pool: 5
username:
password:
test: &TEST
adapter: postgresql
encoding: utf8
database: project_test
pool: 5
username: name
password:
production:
adapter: postgresql
encoding: utf8
database: project_production
pool: 5
username: name
password:
cucumber:
<<: *TEST
Thanks for the help.
Upvotes: 4
Views: 7507
Reputation: 191
First, to find your pg_hba.conf :
sudo find / -name "pg_hba.conf"
It is /var/lib/pgsql/data/pg_hba.conf on my system.
Make sure to change this line in pg_hba.conf :
local all all local
to :
local all all md5
Lastly, restart postgresql :
OS X:
launchctl unload ~/Library/LaunchAgents/org.postgresql.postgres.plist
launchctl load ~/Library/LaunchAgents/org.postgresql.postgres.plist
Systemd:
sudo systemctl restart postgresql.service
SysVinit:
sudo service postgresql restart
Upvotes: 5
Reputation: 471
I used this tutorial "How To Setup Ruby on Rails with Postgres"
And in my database.yml inserted this line:
........
default: &default
adapter: postgresql
encoding: unicode
username: user
password: password
pool: 5
host: localhost
.........
Upvotes: 1