PostgreSQL:显示具体用户的所有权限

PostgreSQL: Show all the privileges for a concrete user

如何查询 Postgres 数据字典以找出特定用户拥有的所有权限。

我一直在寻找解决方案,但我找不到任何东西。谢谢,美好的一天

table 权限:

select 
 * 
from information_schema.role_table_grants 
where grantee='YOUR_USER'
;

所有权:

select 
   * 
from pg_tables 
where tableowner = 'YOUR_USER'
;

架构权限:

select  
  r.usename as grantor, e.usename as grantee, nspname, privilege_type, is_grantable
from pg_namespace
join lateral (
  SELECT
    *
  from
    aclexplode(nspacl) as x
) a on true
join pg_user e on a.grantee = e.usesysid
join pg_user r on a.grantor = r.usesysid 
 where e.usename = 'YOUR_USER'
;

这条命令对我很有帮助:

\l

我是这样使用的:

postgres=# \l

                        List of databases
 Name   | Owner    | Encoding | Collate | Ctype |          Access privileges          
------------------------------+-----------------+----------+---------+-------+-------------------------------------
 mydb1  | postgres | UTF8     | en_NG   | en_NG | =Tc/postgres                       +
        |          |          |         |       | postgres=CTc/postgres              +
        |          |          |         |       | myuser=CTc/postgres
 mydb2  | postgres | UTF8     | en_NG   | en_NG | =Tc/postgres                       +
        |          |          |         |       | postgres=CTc/postgres              +
        |          |          |         |       | my_user=CTc/postgres

资源PostgreSQL: List the database privileges using psql

就这些了。

希望对您有所帮助

这是最适合我的方法。简短而干净。

\du 列出所有用户帐户和角色,\du+ 是显示更多信息的扩展版本。

# \du
                                        List of roles
     Role name      |                         Attributes                         | Member of
--------------------+------------------------------------------------------------+-----------
 padmin             | Superuser, Create role, Create DB                          | {}
 test               |                                                            | {}
 postgres           | Superuser, Create role, Create DB, Replication, Bypass RLS | {}
 root               | Superuser, Create role, Create DB                          | {}
# \du+
                                               List of roles
     Role name      |                         Attributes                         | Member of | Description
--------------------+------------------------------------------------------------+-----------+-------------
 padmin             | Superuser, Create role, Create DB                          | {}        |
 test               |                                                            | {}        |
 postgres           | Superuser, Create role, Create DB, Replication, Bypass RLS | {}        |
 root               | Superuser, Create role, Create DB                          | {}        |