我得到了错误:

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时也不会显示。

知道我哪里错了吗?


当前回答

如果你在使用rails时遇到了这个问题,并且你知道你已经创建了用户名和密码以及正确的权限,那么你只需要在你的数据库末尾添加以下内容。yml文件。

host: localhost

整个文件如下所示

development:
  adapter: postgresql
  encoding: unicode
  database: myapp_development
  pool: 5
  username: root
  password: admin
  host: localhost

你根本不需要修改pg_hba.conf文件。快乐的编码

其他回答

我也有同样的问题。

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

然后做出改变。

我在克隆服务器上移动数据目录,登录postgres时遇到了麻烦。像这样重置postgres密码对我有用。

root# su postgres
postgres$ psql -U postgres
psql (9.3.6) 
Type "help" for help. 
postgres=#\password 
Enter new password: 
Enter it again: 
postgres=#

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

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

如果您试图在Cloud 9中定位此文件,您可以这样做

sudo vim /var/lib/pgsql9/data/pg_hba.conf

按I键编辑/插入,按ESC键3次,输入:wq保存文件并退出

在我的情况下,我甚至无法编辑或查看pg_hba.conf文件的内容。

奏效的方法是:

/etc/postgresql/14/main$ sudo vi pg_hba.conf

具有sudo权限的Vi编辑器。