PG::ConnectionBad: 致命:用户“用户名"错误的对等身份验证失败 [英] PG::ConnectionBad: FATAL: Peer authentication failed for user 'username' error

查看:57
本文介绍了PG::ConnectionBad: 致命:用户“用户名"错误的对等身份验证失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试使用 User.connection 或 generic-table.connection 连接到我的 pg 数据库时,出现此错误

When I try to connect to my pg database using User.connection or generic-table.connection I get this error

PG::ConnectionBad:致命:用户用户名"的对等身份验证失败

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

我仔细检查了我的 database.yml,它看起来不错.我认为问题出在我的 pg_bha.conf 文件上?我现在在我的应用或系统中找不到这个文件.

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.

数据库.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.

推荐答案

首先,找到你的pg_hba.conf:

First, to find your pg_hba.conf :

sudo find/-name "pg_hba.conf"

在我的系统上是/var/lib/pgsql/data/pg_hba.conf.

It is /var/lib/pgsql/data/pg_hba.conf on my system.

确保在 pg_hba.conf 中更改这一行:

Make sure to change this line in pg_hba.conf :

local all all local

到:

local all all md5

最后,重启 postgresql :

Lastly, restart postgresql :

OS X:

launchctl 卸载 ~/Library/LaunchAgents/org.postgresql.postgres.plist

launchctl load ~/Library/LaunchAgents/org.postgresql.postgres.plist

系统化:

sudo systemctl restart postgresql.service

SysVinit:

sudo service postgresql restart

这篇关于PG::ConnectionBad: 致命:用户“用户名"错误的对等身份验证失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆