PostgreSQL 用户列表
我想获取 psql 中某个数据库的用户列表 - 例如“template0”。用户是谁?或者对于“template1”数据库: - 那里的用户是谁?
已经尝试过:
\du+ -- no database is Listed not Users
Select * from "pg_users"; -- no database is listed
I want to get a list of users for a certain database in psql - for example "template0". Who are the users? Or for "template1" database: - who are the users there?
Already tried:
\du+ -- no database is Listed not Users
Select * from "pg_users"; -- no database is listed
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
用户实际上并不是“为了数据库”,他们是为了集群,并被授予不同的访问数据库的权限。要列出用户
\du
应该可以,但您需要连接。类似命令行提示符的操作应该可以。 (或连接到数据库时 psql 提示符下的
\du
)。User aren't actually, "for the database", they're for cluster and are given different permissions to access databases. To list users
\du
should do, but you need to be connected. Something likefrom the command line prompt should do. (or
\du
from psql prompt when you are connected to the database).您必须了解,在 PostgreSQL 中,用户是每个数据库集群的。 @Michael 已经演示了如何获取这些列表。
因此,除非您使用
REVOKE< 明确限制特定数据库的权限/code>
和
GRANT
,集群中的所有用户都具有对集群中任何数据库的基本访问权限。要确定特定用户实际上是否拥有数据库的特定权限(“CONNECT”):
有关手册中的权限函数。
要确定特定数据库的所有特定权限:
如果没有应用特定限制,您将获得
datacl
的NULL
。除此之外,您还可以在
pg_hba.conf
文件。那是较低的水平。如果 pg_hba.conf 不允许用户连接,即使数据库本身允许访问,用户甚至无法连接。You must understand that in PostgreSQL users are per database cluster. @Michael already demonstrates how to get a list of those.
So, unless you restrict permissions for a particular databases explicitly with
REVOKE
andGRANT
, all users in the cluster have basic access to any database in the cluster.To determine, whether a specific user actually has a certain privilege ('CONNECT') for a database:
More about privilege functions in the manual.
To determine all specific privileges for a specific database:
You get
NULL
fordatacl
if no specific restrictions apply.In addition to that you can restrict access per database and per user in the
pg_hba.conf
file. That's on a lower level. The user cannot even connect, ifpg_hba.conf
won't let him, even if the database itself would allow access.要列出角色/用户,
请从 pg_roles 中选择 rolname;
To list roles/user
select rolname from pg_roles;