我得到了错误:

FATAL: Peer authentication failed for user "postgres"

当我尝试让postgres与Rails一起工作时。

这是pg_hba.conf,我的数据库。Yml,以及完整跟踪的转储。

我在pg_hba中将身份验证更改为md5,并尝试了不同的方法,但似乎都不起作用。

我还尝试按照Rails 3.2创建一个新用户和数据库,FATAL: Peer authentication failed for user (PG::Error)

但是它们不会在pgadmin上显示,甚至当我运行sudo -u postgres psql -l时也不会显示。

知道我哪里错了吗?


当前回答

最简单的解决方案,无需更改配置。(ubuntu) 修改用户,然后连接数据库cli。

sudo -i -u postgres

psql

摘自https://www.digitalocean.com/community/tutorials/how-to-install-and-use-postgresql-on-ubuntu-18-04

其他回答

我也有同样的问题。

depa的解决方案是绝对正确的。

只要确保你有一个用户配置使用PostgreSQL。

检查文件:

$ ls /etc/postgresql/9.1/main/pg_hba.conf -l

这个文件的权限应该给你注册psql的用户。

进一步。如果你到现在还好…

按照@depa的指示更新。

i.e.

$ sudo nano /etc/postgresql/9.1/main/pg_hba.conf

然后做出改变。

在CentOS 7, PG 10上,文件路径为

/var/lib/pgsql/10/data/pg_hba.conf

修改pg_hba.conf中的METHOD peer为trust (/etc/postgresql/9.1/main/pg_hba.conf |第85行)可以解决这个问题。添加md5需要密码,因此如果需要避免使用密码,请使用trust而不是md5。

另外,如果您没有从postgres帐户访问脚本的权限,您可以使用下面的方法。

$ cat ./init-user-db.sh | sudo -i -u postgres bash

您只需要将METHOD设置为信任。

#TYPE  DATABASE        USER            ADDRESS                 METHOD
local    all             all                                     trust

并重新加载postgres服务器。

# service postgresql-9.5 reload

修改pg_hba.conf不需要重启postgres服务器。重新加载。