PostgreSQL为什么将用户和组合并为角色? [英] Why did PostgreSQL merge users and groups into roles?

查看:91
本文介绍了PostgreSQL为什么将用户和组合并为角色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

来自 PostgreSQL文档


角色的概念包含了用户和组的概念。在8.1之前的
PostgreSQL版本中,用户和组是不同种类的
实体,但是现在只有角色。任何角色都可以充当用户,
a组或两者兼有。


他们为什么在8.1中进行此更改? / p>

也许从C编码器的角度来看,使用单个Role类(结构)更容易?



< a href = http://www.postgresql.org/docs/current/static/role-membership.html rel = noreferrer>更多详细信息:



CREATE USER等同于CREATE ROLE,除了CREATE USER 授予用户/角色LOGIN权限。

b
$ b

(我将为我的Web应用程序设计一个权限系统,因此对此我很感兴趣。)

解决方案

合并具有很多优点,而没有缺点。例如,您现在可以通过添加/删除 LOGIN 特权来无缝地将用户转换为组,反之亦然。

  ALTER ROLE myrole登录; 
ALTER ROLE myrole NOLOGIN;

或者您可以 GRANT 具有以下任何其他登录角色(用户)或非登录角色(组)的成员身份:

  GRANT joe提起诉讼; 

您仍然可以:

 创建用户邮件; 

那只是具有登录权限的角色。或者:

 创建组工作人员; 

实际上是与现在创建角色 相同。



手册具有全部功能。


From the PostgreSQL docs:

The concept of roles subsumes the concepts of "users" and "groups". In PostgreSQL versions before 8.1, users and groups were distinct kinds of entities, but now there are only roles. Any role can act as a user, a group, or both.

Why did they make this change in 8.1?

Perhaps it's easier from the C coders point of view, with a single Role class (struct)?

More details:

CREATE USER is equivalent to CREATE ROLE except that CREATE USER gives the LOGIN permission to the user/role.

(I'm about to design a permission system for my webapp, hence I'm interested in this.)

解决方案

The merge has many advantages and no disadvantages. For instance, you can now seamlessly convert a "user" to a "group" and vice versa by adding / removing the LOGIN privilege.

ALTER ROLE myrole LOGIN;
ALTER ROLE myrole NOLOGIN;

Or you can GRANT membership in any other login ("user") or non-login role ("group") to a role:

GRANT joe TO sue;

You can still:

CREATE USER james;

That's just a role with login privilege now. Or:

CREATE GROUP workers;

That's effectively the same as CREATE ROLE now.

The manual has it all.

这篇关于PostgreSQL为什么将用户和组合并为角色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆