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

  • 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.
主站蜘蛛池模板: 广宗县| 运城市| 苍溪县| 安庆市| 石景山区| 金湖县| 怀柔区| 皋兰县| 清丰县| 乐陵市| 唐海县| 普兰县| 余庆县| 綦江县| 敦化市| 韶关市| 翁牛特旗| 冕宁县| 庆阳市| 全南县| 南岸区| 巩留县| 枣强县| 连城县| 监利县| 石门县| 泸定县| 南江县| 屏东市| 隆化县| 巴塘县| 普定县| 泌阳县| 明溪县| 伊川县| 绥宁县| 社旗县| 桂阳县| 海林市| 拜城县| 陇西县|