pg許可權相關

slnngk發表於2024-05-22

1.檢視某個表授予的許可權

進入到具體的庫查詢

SELECT grantee,table_schema,table_name,string_agg( privilege_type,', ' ) as privilege_type
FROM information_schema.role_table_grants
WHERE table_name='tb_aa'
group by grantee,table_schema,table_name;

   grantee    | table_schema | table_name |                        privilege_type                         
--------------+--------------+------------+---------------------------------------------------------------
 hxl          | public       | tb_aa      | INSERT, SELECT, UPDATE, DELETE, TRUNCATE, REFERENCES, TRIGGER
 logical_user | public       | tb_aa      | SELECT
(2 rows)

2.根據使用者查詢
進入到具體的庫查詢

SELECT grantee,table_schema,table_name, string_agg( privilege_type,', ' ) as privilege_type 
FROM information_schema.role_table_grants 
where grantee='hxl' group by table_name,table_schema,grantee;

   grantee    | table_schema | table_name | privilege_type 
--------------+--------------+------------+----------------
 logical_user | public       | tb_aa      | SELECT
 logical_user | public       | tb_bb      | SELECT
 logical_user | public       | tb_cc      | SELECT

相關文章