3
votes

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.
2
can you post your database.yml codeSonalkumar sute

2 Answers

5
votes

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

1
votes

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
.........