官术网_书友最值得收藏!

  • Learning PostgreSQL 11
  • Salahaldin Juba Andrey Volkov
  • 421字
  • 2021-07-02 13:11:48

Roles

Roles belong to the PostgreSQL server cluster and not to a certain database. A role can either be a database user or a database group. The role concept subsumes the concepts of users and groups in the old PostgreSQL versions. For compatibility reasons, with PostgreSQL version 8.1 and later, the CREATE USER and CREATE GROUP SQL commands are still supported.

The roles have several attributes, which are as follows:

  • SUPERUSER: A superuser role can bypass all permission checks except the LOGIN attribute.
  • LOGIN: A role with the LOGIN attribute can be used by a client to connect to a database.
  • CREATEDB: A role with the create database attribute can create databases.
  • CREATEROLE: A role with this feature enabled can create, delete, and alter other roles.
  • REPLICATION: A role with this attribute can be used to stream replication.
  • PASSWORD: The PASSWORD role can be used with the md5 and scram-sha-256 authentication method. The password expiration can be controlled by specifying the validity period. Note that this password differs from the OS password. In newer versions of PostgreSQL server—mainly 10 and 11—it's recommended to use scram-sha-256, instead of md5, because it's more secure.
  • CONNECTION LIMIT: This specifies the number of concurrent connections that the user can initiate. Connection creation consumes hardware resources; thus, it's recommended to use connection pooling tools such as Pgpool-IIYandex OdysseyPgBouncer, or some APIs, such as Apache DBCP or c3p0.
  • INHERIT: If specified, the role will inherit the privileges assigned to the roles that it's a member of. If not specified, INHERIT is the default.
  • BYPASSRLS: If specified, this role can bypass row-level security (RLS).
During the installation of PostgreSQL, the postgres superuser role is created.  CREATE USER is equivalent to CREATEROLE with the LOGIN option, and CREATE GROUP is equivalent to CREATEROLE with the NOLOGIN option.

A role can be a member of another role to simplify accessing and managing database permissions; for example, you can create a role with no login, also known as a group, and grant it permission to access the database objects. If a new role needs to access the same database objects with the same permissions as the group, the new role could be assigned a membership to this group. This is achieved by the GRANT and REVOKE SQL commands, which are discussed in detail in Chapter 11, PostgreSQL Security.

The roles of a cluster don't necessarily have privileges to access every database in the cluster.
主站蜘蛛池模板: 朝阳县| 察隅县| 赣州市| 宁陕县| 海晏县| 平武县| 湛江市| 遂川县| 永安市| 银川市| 冕宁县| 盱眙县| 沁源县| 黄龙县| 井冈山市| 邵阳市| 明光市| 渭源县| 分宜县| 涪陵区| 同德县| 宜宾市| 方山县| 万年县| 仙居县| 宁晋县| 泉州市| 宝丰县| 五华县| 冕宁县| 昭通市| 大关县| 开江县| 双牌县| 江安县| 中方县| 广河县| 漾濞| 乌恰县| 蒲城县| 申扎县|