【问题标题】:PG::ConnectionBad: FATAL: Peer authentication failed for user 'username' errorPG::ConnectionBad: FATAL: Peer authentication failed for user 'username' 错误
【发布时间】:2015-02-09 13:53:45
【问题描述】:

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

PG::ConnectionBad: FATAL: 用户“用户名”的对等身份验证失败

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

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

【问题讨论】:

  • 你能贴出你的database.yml代码吗

标签: ruby-on-rails postgresql


【解决方案1】:

首先,找到你的 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

系统化:

sudo systemctl restart postgresql.service

SysVinit:

sudo service postgresql restart

【讨论】:

  • 在 Ubuntu 14.04 下,使用上面的 SysVinit 命令重启你的 PostgreSQL 服务。另外,非常感谢,这非常有效。
【解决方案2】:

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

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

........
default: &default
adapter: postgresql
encoding: unicode
username: user
password: password
pool: 5
host: localhost
.........

【讨论】:

    猜你喜欢
    • 2019-06-23
    • 2013-03-26
    • 2021-10-19
    • 2021-11-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多