postgres数据库查看用户权限

1、查看某用户的表权限
select * from information_schema.table_privileges where grantee='user_name';
2、查看usage权限表
select * from information_schema.usage_privileges where grantee='user_name';
3、查看存储过程函数相关权限表
select * from information_schema.routine_privileges where grantee='user_name';
4、建用户授权
create user user_name;
alter user user_name with password '';
alter user user_name with CONNECTION LIMIT  20;#连接数限制
PostgreSQL 中,有多种方式可以查询数据库用户对表的权限。 ### 使用 `information_schema.table_privileges` 视图 `information_schema.table_privileges` 视图提供了关于表权限的信息,可以通过以下 SQL 语句查询特定用户对表的权限: ```sql SELECT grantee, table_catalog, table_schema, table_name, privilege_type FROM information_schema.table_privileges WHERE grantee = 'your_username'; ``` 将 `your_username` 替换为你要查询的实际用户名,该查询会返回该用户在各个表上被授予的权限信息。 ### 使用 `pg_class` 表的 `relacl` 字段 `pg_class` 表存储了数据库中所有表和索引的信息,`relacl` 字段包含了表的访问控制列表(ACL)。可以通过以下 SQL 语句查询用户对表的权限: ```sql SELECT relname, relacl FROM pg_class WHERE relacl::text LIKE '%your_username%'; ``` 同样,将 `your_username` 替换为你要查询的实际用户名。不过,`relacl` 字段的内容是一种特殊的格式,需要进一步解析才能明确具体权限。 ### 查询某个角色在某个表中的权限 如果要查询某个角色(用户)在特定表中的权限,可以结合 `pg_class` 和 `pg_roles` 表: ```sql SELECT c.relname, r.rolname, array_to_string(c.relacl, ', ') FROM pg_class c JOIN pg_roles r ON c.relacl::text LIKE '%' || r.rolname || '%' WHERE r.rolname = 'your_username' AND c.relkind = 'r'; -- 仅查询普通表 ``` 将 `your_username` 替换为要查询的用户名。
评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值