出现错误:尝试让 pgsql 与 rails 一起工作时,用户“postgres"的对等身份验证失败 [英] Getting error: Peer authentication failed for user "postgres", when trying to get pgsql working with rails

查看:21
本文介绍了出现错误:尝试让 pgsql 与 rails 一起工作时,用户“postgres"的对等身份验证失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我收到错误:

致命:用户postgres"的对等身份验证失败

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

这是我的 pg_hba.conf,我的 database.yml 和一个 完整跟踪的转储.

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

我还尝试按照 Rails 3.2,致命:用户的对等身份验证失败(PG::Error)

但是它们没有出现在 pgadmin 上,甚至在我运行 sudo -u postgres psql -l 时也没有出现.

知道我哪里出错了吗?

解决方案

问题还是出在你的pg_hba.conf文件*上.

这一行:

local 所有 postgres peer

应该是:

local 所有 postgres md5

<块引用>

* 这个文件的位置不是很一致.命令 locate pg_hba.conf 应该会有所帮助;这里有一些例子:/etc/postgresql/*/main/pg_hba.conf/var/lib/pgsql/data/pg_hba.conf.

更改此文件后,不要忘记重新启动 PostgreSQL 服务器.如果您使用的是 Linux,那将是 sudo service postgresql restart.

这些是根据 官方 PostgreSQL 文档对这两个选项的简要说明身份验证方法.

对等身份验证

<块引用>

对等身份验证方法通过获取客户端的内核中的操作系统用户名并将其用作允许的数据库用户名(带有可选的用户名映射).这种方法是仅支持本地连接.

密码认证

<块引用>

基于密码的身份验证方法是 md5 和密码.这些除了密码的发送方式外,方法的操作类似跨连接,分别是 MD5 哈希和明文.

如果您完全担心密码嗅探"攻击然后md5是首选.如果可能,应始终避免使用普通密码.但是,md5 不能与 db_user_namespace 功能一起使用.如果连接受 SSL 加密保护,然后可以使用密码安全(尽管 SSL 证书身份验证可能是更好的选择如果依赖于使用 SSL).

pg_hba.conf 的示例位置:
/etc/postgresql/9.1/main/pg_hba.conf

I'm getting the error:

FATAL: Peer authentication failed for user "postgres"

when I try to make postgres work with Rails.

Here's my pg_hba.conf, my database.yml, and a dump of the full trace.

I changed authentication to md5 in pg_hba and tried different things, but none seem to work.

I also tried creating a new user and database as per Rails 3.2, FATAL: Peer authentication failed for user (PG::Error)

But they don't show up on pgadmin or even when I run sudo -u postgres psql -l.

Any idea where I'm going wrong?

解决方案

The problem is still your pg_hba.conf file*.

This line:

local   all             postgres                                peer

Should be:

local   all             postgres                                md5

* The location of this file isn't very consistent. The command locate pg_hba.conf should help; here's some examples: /etc/postgresql/*/main/pg_hba.conf and /var/lib/pgsql/data/pg_hba.conf.

After altering this file, don't forget to restart your PostgreSQL server. If you're on Linux, that would be sudo service postgresql restart.

These are brief descriptions of both options according to the official PostgreSQL docs on authentication methods.

Peer authentication

The peer authentication method works by obtaining the client's operating system user name from the kernel and using it as the allowed database user name (with optional user name mapping). This method is only supported on local connections.

Password authentication

The password-based authentication methods are md5 and password. These methods operate similarly except for the way that the password is sent across the connection, namely MD5-hashed and clear-text respectively.

If you are at all concerned about password "sniffing" attacks then md5 is preferred. Plain password should always be avoided if possible. However, md5 cannot be used with the db_user_namespace feature. If the connection is protected by SSL encryption then password can be used safely (though SSL certificate authentication might be a better choice if one is depending on using SSL).

Sample location for pg_hba.conf:
/etc/postgresql/9.1/main/pg_hba.conf

这篇关于出现错误:尝试让 pgsql 与 rails 一起工作时,用户“postgres"的对等身份验证失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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