我收到错误:
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 methods 对 peer
与 md5
选项的简要描述.
对等认证
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/