PostgreSQL:查看数据库连接权限

发布于 2024-11-02 07:04:19 字数 178 浏览 0 评论 0原文

如何查看已颁发的用户GRANT CONNECT ON DATABASE致<用户>

  • \dp - 列出表/视图权限
  • \dn+ - 列出架构权限
  • \l+ 不列出可以访问数据库的所有用户

How do you view users that have been issued GRANT CONNECT ON DATABASE <database> TO <user>?

  • \dp - lists table/view permissions
  • \dn+ - lists schema permissions
  • \l+ does not list all users that can access the database

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

×纯※雪 2024-11-09 07:04:19

如果 \l+ 命令只显示一些具有连接到数据库的权限/特权的用户,那就有点奇怪了。我自己无法在 PostgreSQL 8.4 安装(Ubuntu 10.04 LTS)上重复这一点。您使用什么版本?

无论如何,也许您可​​以检查保存该特定数据库的 ACL 的表,并从中推断出用户是否具有正确的权限:

SELECT datname as "Relation", datacl as "Access permissions" FROM pg_database WHERE datname = 'databasename';

如果您只想检查一个用户,您可以执行以下操作:

SELECT * FROM has_database_privilege('username', 'database', 'connect');

权限/特权如何来解释?权限应这样理解:

user = privileges / granted by 

省略用户意味着 PUBLIC 被授予权限,即所有角色。例如,如果权限是=Tc/postgres,那么所有角色都可以连接并在该特定数据库中创建临时表,并且授予该权限的是postgres用户。

PostgreSQL 站点上有一个概要解释了不同的权限: https://www.postgresql.org/docs/current/ddl-priv.html#PRIVILEGE-ABBREVS-TABLE

rolename=xxxx -- privileges granted to a role
        =xxxx -- privileges granted to PUBLIC

            r -- SELECT ("read")
            w -- UPDATE ("write")
            a -- INSERT ("append")
            d -- DELETE
            D -- TRUNCATE
            x -- REFERENCES
            t -- TRIGGER
            X -- EXECUTE
            U -- USAGE
            C -- CREATE
            c -- CONNECT
            T -- TEMPORARY
      arwdDxt -- ALL PRIVILEGES (for tables, varies for other objects)
            * -- grant option for preceding privilege

        /yyyy -- role that granted this privilege

A bit odd if the \l+ command just displays some of the users that have permission/privilege to connect to the database. I could not repeat that myself on a PostgreSQL 8.4 installation (Ubuntu 10.04 LTS). What version are you using?

Anyway, perhaps you could check the table holding the ACL's for that particular database and from that deduce whether the user has the correct privileges or not:

SELECT datname as "Relation", datacl as "Access permissions" FROM pg_database WHERE datname = 'databasename';

If you just want to check one user you could do something like this:

SELECT * FROM has_database_privilege('username', 'database', 'connect');

How are the permissions/privileges to interpreted? The privileges are to be read like this:

user = privileges / granted by 

Omitting user means that PUBLIC is granted the privilege, ie all roles. For example if the privilege is =Tc/postgres then all roles may connect and create temporary tables in that particular database and it is the postgres user who granted the privilege.

There is a synopsis at the PostgreSQL site explaining the different privileges: https://www.postgresql.org/docs/current/ddl-priv.html#PRIVILEGE-ABBREVS-TABLE.

rolename=xxxx -- privileges granted to a role
        =xxxx -- privileges granted to PUBLIC

            r -- SELECT ("read")
            w -- UPDATE ("write")
            a -- INSERT ("append")
            d -- DELETE
            D -- TRUNCATE
            x -- REFERENCES
            t -- TRIGGER
            X -- EXECUTE
            U -- USAGE
            C -- CREATE
            c -- CONNECT
            T -- TEMPORARY
      arwdDxt -- ALL PRIVILEGES (for tables, varies for other objects)
            * -- grant option for preceding privilege

        /yyyy -- role that granted this privilege
柳若烟 2024-11-09 07:04:19

我正在使用 postgres 8.4 和 postgres 9.0 中的 psql,并且命令 \l\l+ 为我提供了我可以输入的列 Access Privileges

<user_name>=c/<database_name>

之前我根据需要向用户授予了连接权限。

正如页面上所述 http://www.postgresql.org/docs /9.0/static/sql-grant.html,这里的c字母表示Connect

I'm using psql from postgres 8.4 and postgres 9.0, and the command \l or \l+ gives me column Access Privileges where I have entry:

<user_name>=c/<database_name>

and earlier I gave the user the connect privilege as you wanted.

As it states on the page http://www.postgresql.org/docs/9.0/static/sql-grant.html, the c letter here means Connect.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文