现有用户在PostgreSQL上登录失败 [英] Login Failed with Existing User on PostgreSQL
问题描述
我刚刚开始使用PostgreSQL.我的目标是在postgres之外创建一个具有所有相同特权的新用户,并为我的ror应用程序创建一个数据库.我可以在postgres下登录.我确实创建了一个名为Jason
的用户,这很好,但是当我执行sudo -u username psql
时,会收到以下错误...
I just started playing around with PostgreSQL. My goal is to create a new user outside of postgres with all of the same privileges and create a database for my ror app. I'm able to login under postgres. I did create an user named Jason
, which is good, however when I do sudo -u username psql
I receive the following error...
sudo: unknown user: Jason
sudo: unable to initialize policy plugin
我可以通过在postgres控制台中同时检查\ dg来确定用户名是否存在.
I can determine that the username exists by checking both \dg in my postgres console.
List of roles
Role name | Attributes | Member of
-----------+------------------------------------------------+-----------
Jason | Superuser, Create role, Create DB, Replication | {}
postgres | Superuser, Create role, Create DB, Replication | {}
是什么导致此问题?另外,我检查了我的本地pg_hba.conf
并得到了我认为正确的设置.
What's causing this problem? Also, I checked my local pg_hba.conf
and have what I believe to be the correct settings.
# Allow replication connections from localhost, by a user with the
# replication privilege.
#local replication postgres peer
#host replication postgres 127.0.0.1/32 md5
#host replication postgres ::1/128 md5
推荐答案
您正在将系统用户与数据库用户混淆.错误消息来自sudo
,与PostgreSQL无关.
You are confusing system user with database user. The error message comes from sudo
and has nothing to do with PostgreSQL at all.
以数据库用户Jason的身份登录:
To log in as database user Jason:
psql -U Jason
当然,只要未设置无密码访问,就需要提供密码. 对等身份验证仅适用于同名("Jason")的系统用户.
优秀手册中有关psql
此处的更多信息,以及有关身份验证方法
You need to supply a password, of course, as long as password-less access is not set up. Peer authentication only works for a system user of the same name ("Jason").
More in the excellent manual about psql
here and about authentication methods here.
这篇关于现有用户在PostgreSQL上登录失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!