ruby-on-rails - 尝试让 pgsql 使用 rails 时出现错误 : Peer authentication failed for user "postgres",

标签 ruby-on-rails postgresql

我收到错误:

FATAL: Peer authentication failed for user "postgres"

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

这是我的 pg_hba.conf , 我的 database.yml , 和一个 dump of the full trace .

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

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

但它们不会出现在 pgadmin 上,甚至在我运行 sudo -u postgres psql -l 时也不会出现。

知道我哪里出错了吗?

最佳答案

问题仍然是您的 pg_hba.conf 文件*。

这一行:

local   all             postgres                                peer

应该是:

local   all             postgres                                md5

更改此文件后,不要忘记重新启动 PostgreSQL 服务器。如果你在 Linux 上,那将是 sudo systemctl restart postgresql(在旧系统上:sudo service postgresql restart)。


定位hba.conf

请注意,此文件的位置不是很一致。

您可以使用 locate pg_hba.conf 或询问 PostgreSQL SHOW hba_file; 来发现文件位置。

通常的位置是 /etc/postgresql/[version]/main/pg_hba.conf/var/lib/pgsql/data/pg_hba.conf


这些是根据 official PostgreSQL docs on authentication methodspeermd5 选项的简要描述.

对等认证

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.

密码认证

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).

关于ruby-on-rails - 尝试让 pgsql 使用 rails 时出现错误 : Peer authentication failed for user "postgres",,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18664074/

相关文章:

ruby-on-rails - PG::UndefinedTable: 错误: 缺少 FROM 子句 — 使用两个模型进行搜索 Rails

mysql - 将 NULL 值插入 postgreSQL 中的 TIMESTAMP 字段

使用 V8 和 PostgreSQL 的 Javascript 序列化和性能

django - 通过 psycopg2 连接执行的查询数

json - 从 PostgreSQL 中的 json 列解压数据

javascript - 如何为我的网站创建需要用户身份验证的书签

ruby-on-rails - 类型错误 : superclass mismatch for class Task

ruby-on-rails - Bundler - 无法加载完全相同的 gem 的 2 个不同版本?

mysql - 使用 MySQL 子句 "Use index(' index_name')"using ActiveRecord 的最佳方式

sql - 查询 PostgreSQL 的 Open-High-Low-Close (OHLC) 报告