显示特定用户的所有特权

Pyt*_*820 4 postgresql privileges postgresql-9.1 psql

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

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

Vao*_*sun 9

表权限:

select 
 * 
from information_schema.role_table_grants 
where grantee='YOUR_USER'
;
Run Code Online (Sandbox Code Playgroud)

所有权:

select 
   * 
from pg_tables 
where tableowner = 'YOUR_USER'
;
Run Code Online (Sandbox Code Playgroud)

架构权限:

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'
;
Run Code Online (Sandbox Code Playgroud)

  • 不确定这是做什么的,但所有查询结果都是空的。然而,我的用户可以访问他们自己的数据库、表,甚至可以查看外部数据库并在那里创建/删除新表!这个答案没有帮助。 (3认同)
  • @ygoe:如果用户拥有表(或数据库),则不存在特殊授予,因为对象的所有者始终具有对该对象的完全访问权限(无需授予) (3认同)

Mr.*_*ley 8

这对我来说是最好的。简短而干净。

\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                          | {}
Run Code Online (Sandbox Code Playgroud)
# \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                          | {}        |
Run Code Online (Sandbox Code Playgroud)


Pro*_*ton 6

这个命令对我很有帮助:

\l
Run Code Online (Sandbox Code Playgroud)

我是这样使用的

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
Run Code Online (Sandbox Code Playgroud)

资源PostgreSQL:使用 psql 列出数据库权限

就这样。

我希望这有帮助