数据库用户权限管理(二)

本文通过具体实例展示了在HighGo数据库中,不同类型的用户权限之间存在明确的界限,即使将角色权限授予其他用户,也不能混用这些权限。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

作者:瀚高PG实验室 (Highgo PG Lab)-海无涯

上次说到数据库用户的权限分为两大类,后来做测试的时候发现一个问题,就是这两大类权限是有很强的“界限”的。

举例如下:

highgo=# \du
                                   List of roles
 Role name |                         Attributes                         | Member of 
-----------+------------------------------------------------------------+-----------
 highgo    | Superuser, Create role, Create DB, Replication, Bypass RLS | {}
 test      |                                                            | {}
 trole     | Create role                                                | {}


highgo=# \c highgo test;

PSQL: Release 4.1.1
Connected to:
HighGo Database V4.1 Enterprise Edition Release 4.1.1 - 64-bit Production

You are now connected to database "highgo" as user "test".
highgo=> create role eee;
错误:  42501: 创建角色的权限不够
highgo=> \c highgo trole

PSQL: Release 4.1.1
Connected to:
HighGo Database V4.1 Enterprise Edition Release 4.1.1 - 64-bit Production

You are now connected to database "highgo" as user "trole".
highgo=> select user;
 current_user 
--------------
 trole
(1 row)

highgo=> create role qqq;
CREATE ROLE
连接超级用户更改权限:
highgo=# grant trole to test;
GRANT ROLE
highgo=> \du
                                   List of roles
 Role name |                         Attributes                         | Member of 
-----------+------------------------------------------------------------+-----------
 highgo    | Superuser, Create role, Create DB, Replication, Bypass RLS | {}
 test      |                                                            | {trole}
 trole     | Create role                                                | {}
highgo=# \c highgo test;

PSQL: Release 4.1.1
Connected to:
HighGo Database V4.1 Enterprise Edition Release 4.1.1 - 64-bit Production

You are now connected to database "highgo" as user "test".
highgo=> create role eee;
错误:  42501: 创建角色的权限不够

仍旧不能创建角色,说明两种权限不能混谈。

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值