PG :: ConnectionBad:致命错误:用户'用户名'错误导致对等身份验证失败

时间:2015-02-09 13:53:45

标签: ruby-on-rails postgresql

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

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

我仔细检查了我的database.yml,看起来不错。我认为问题在于我的pg_bha.conf文件?我现在无法在我的应用程序或系统中找到此文件。

的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 个答案:

答案 0 :(得分:5)

首先,找到你的pg_hba.conf:

sudo find / -name "pg_hba.conf"

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

请务必在pg_hba.conf中更改此行:

local all all local

到:

local all all md5

最后,重启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 :(得分:1)

我使用了这个教程"How To Setup Ruby on Rails with Postgres"

在我的database.yml中插入了这一行:

........
default: &default
adapter: postgresql
encoding: unicode
username: user
password: password
pool: 5
host: localhost
.........
相关问题