使用 PostgreSQL 上的现有用户登录失败
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13004297/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Login Failed with Existing User on PostgreSQL
提问by jason328
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...
我刚开始玩 PostgreSQL。我的目标是在 postgres 之外创建一个具有所有相同权限的新用户,并为我的 ror 应用程序创建一个数据库。我可以在 postgres 下登录。我确实创建了一个名为 的用户Jason
,这很好,但是当我这样做时,sudo -u username psql
我收到以下错误...
sudo: unknown user: Jason
sudo: unable to initialize policy plugin
I can determine that the username exists by checking both \dg in my postgres console.
我可以通过检查 postgres 控制台中的两个 \dg 来确定用户名是否存在。
List of roles
Role name | Attributes | Member of
-----------+------------------------------------------------+-----------
Jason | Superuser, Create role, Create DB, Replication | {}
postgres | Superuser, Create role, Create DB, Replication | {}
What's causing this problem? Also, I checked my local pg_hba.conf
and have what I believe to be the correct settings.
是什么导致了这个问题?此外,我检查了我的本地pg_hba.conf
并拥有我认为正确的设置。
# 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
回答by Erwin Brandstetter
You are confusing system userwith database user. The error message comes from sudo
and has nothing to do with PostgreSQL at all.
您将system user与database user混淆了。错误消息来自sudo
PostgreSQL,与 PostgreSQL 完全无关。
To log in as database user Jason:
以数据库用户 Jason 的身份登录:
psql -U Jason
You need to supply a password, of course, as long as password-less access is not set up. Peer authenticationonly works for a system user of the same name ("Jason").
More in the excellent manual about psql
hereand about authentication methods here.
当然,只要未设置无密码访问,您就需要提供密码。 对等身份验证仅适用于同名系统用户(“Jason”)。
更多关于psql
这里的优秀手册和关于这里的身份验证方法。