postgresql 用户和角色有什么区别?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/27709456/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 01:43:48  来源:igfitidea点击:

What is the difference between a user and a role?

postgresql

提问by chopper draw lion4

I know there are other threads that are similar, but I am not sure if they are relevant to Postgres.

我知道还有其他类似的线程,但我不确定它们是否与 Postgres 相关。

I am reading the PostgreSQL documentation which it reads as follows:

我正在阅读 PostgreSQL 文档,其内容如下:

Note: As explained in Chapter 20, PostgreSQL actually does privilege management in terms of "roles". In this chapter, we consistently use database user to mean "role with the LOGIN privilege".

注意:如第 20 章所述,PostgreSQL 实际上是根据“角色”进行权限管理的。在本章中,我们始终使用数据库用户来表示“具有 LOGIN 权限的角色”。

Does this basically mean a role is a database user? Or is there a difference between a role and a user? Do users have the potential to not have full privileges while roles are users who always do have full privileges?

这是否基本上意味着角色是数据库用户?或者角色和用户之间有区别吗?用户是否有可能没有完全权限,而角色是始终拥有完全权限的用户?

回答by IMSoP

Previous versions of Postgres, and some other DB systems, have separate concepts of "groups" (which are granted access to database objects) and "users" (who can login, and are members of one or more groups).

以前版本的 Postgres 和其他一些数据库系统具有“组”(被授予访问数据库对象的权限)和“用户”(可以登录,并且是一个或多个组的成员)的独立概念。

In modern versions of Postgres, the two concepts have been merged: a "role" can have the ability to login, the ability to "inherit" from other roles (like a user being a member of a group, or a group being a member of another group), and access to database objects.

在现代版本的 Postgres 中,这两个概念已经合并:“角色”可以具有登录能力,能够“继承”其他角色(例如用户是组的成员,或组是成员)另一个组),并访问数据库对象。

For convenience, many tools and manuals refer to any user with login permission as a "user" or "login role", and any without as a "group" or "group role", since it is useful and common practice to keep roughly to that structure. This is entirely a convention of terminology, and to understand the permissions, you need only understand the options available when creating rolesand granting them access.

为方便起见,许多工具和手册将具有登录权限的任何用户称为“用户”或“登录角色”,而将没有登录权限的任何用户称为“组”或“组角色”,因为粗略地保持那个结构。这完全是术语的约定,要了解权限,您只需了解创建角色授予他们访问权限时可用的选项。

Again purely for convenience, Postgres still accepts commands using the old terminology, such as CREATE USERand CREATE GROUPwhich are both aliases for CREATE ROLE. If you write CREATE USER, the LOGINpermission will be added to the new role by default, to emulate the old behaviour when that was a separate command.

再次纯粹为了方便起见,Postgres 仍然接受使用旧术语的命令,例如CREATE USERCREATE GROUP都是CREATE ROLE. 如果您编写CREATE USERLOGIN默认情况下,权限将添加到新角色,以模拟旧的行为,当这是一个单独的命令时。