Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PG::ConnectionBad: FATAL: Peer authentication failed for user 'username' error

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.
like image 526
Joe Smith Avatar asked Sep 20 '25 02:09

Joe Smith


1 Answers

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

like image 175
James Martinez Avatar answered Sep 22 '25 18:09

James Martinez