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

雨燕双飞 提交于 2021-01-27 12:35:23

问题


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.

回答1:


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




回答2:


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


来源:https://stackoverflow.com/questions/28411333/pgconnectionbad-fatal-peer-authentication-failed-for-user-username-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!