Postgresql 中文操作指南

22.5. Predefined Roles #

PostgreSQL 提供了一组预定义的角色,它们可提供对某些常用特权功能和信息的访问。管理员(包括拥有 CREATEROLE 权限的角色)可以在其环境中将 GRANT 这些角色授予用户和/或其他角色,从而向这些用户提供对指定功能和信息的访问权限。

PostgreSQL provides a set of predefined roles that provide access to certain, commonly needed, privileged capabilities and information. Administrators (including roles that have the CREATEROLE privilege) can GRANT these roles to users and/or other roles in their environment, providing those users with access to the specified capabilities and information.

预定义角色在 Table 22.1中描述。注意,每个角色的特定权限可能会在将来添加到其他功能时发生改变。管理员应监控发行说明中的更改。

The predefined roles are described in Table 22.1. Note that the specific permissions for each of the roles may change in the future as additional capabilities are added. Administrators should monitor the release notes for changes.

Table 22.1. Predefined Roles

Table 22.1. Predefined Roles

Role

Allowed Access

pg_read_all_data

Read all data (tables, views, sequences), as if having SELECT rights on those objects, and USAGE rights on all schemas, even without having it explicitly. This role does not have the role attribute BYPASSRLS set. If RLS is being used, an administrator may wish to set BYPASSRLS on roles which this role is GRANTed to.

pg_write_all_data

Write all data (tables, views, sequences), as if having INSERT, UPDATE, and DELETE rights on those objects, and USAGE rights on all schemas, even without having it explicitly. This role does not have the role attribute BYPASSRLS set. If RLS is being used, an administrator may wish to set BYPASSRLS on roles which this role is GRANTed to.

pg_read_all_settings

Read all configuration variables, even those normally visible only to superusers.

pg_read_all_stats

Read all pg_stat_* views and use various statistics related extensions, even those normally visible only to superusers.

pg_stat_scan_tables

Execute monitoring functions that may take ACCESS SHARE locks on tables, potentially for a long time.

pg_monitor

Read/execute various monitoring views and functions. This role is a member of pg_read_all_settings, pg_read_all_stats and pg_stat_scan_tables.

pg_database_owner

None. Membership consists, implicitly, of the current database owner.

pg_signal_backend

Signal another backend to cancel a query or terminate its session.

pg_read_server_files

Allow reading files from any location the database can access on the server with COPY and other file-access functions.

pg_write_server_files

Allow writing to files in any location the database can access on the server with COPY and other file-access functions.

pg_execute_server_program

Allow executing programs on the database server as the user the database runs as with COPY and other functions which allow executing a server-side program.

pg_checkpoint

Allow executing the CHECKPOINT command.

pg_use_reserved_connections

Allow use of connection slots reserved via reserved_connections.

pg_create_subscription

Allow users with CREATE permission on the database to issue CREATE SUBSCRIPTION.

pg_monitor, pg_read_all_settings, pg_read_all_statspg_stat_scan_tables 角色旨在让管理员能够轻松配置角色以用于监控数据库服务器。它们授予一组常见权限,允许角色读取各种有用的配置设置、统计和其他系统信息,而这些信息通常仅限于超级用户。

The pg_monitor, pg_read_all_settings, pg_read_all_stats and pg_stat_scan_tables roles are intended to allow administrators to easily configure a role for the purpose of monitoring the database server. They grant a set of common privileges allowing the role to read various useful configuration settings, statistics and other system information normally restricted to superusers.

pg_database_owner 角色有一个隐式(依赖于具体情况)成员,即当前数据库的所有者。与其他任何角色一样,它可以拥有对象或接收访问权限的授予。因此,一旦 pg_database_owner 拥有模板数据库中的权限,每个从该模板实例化的数据库的所有者都将行使这些权限。pg_database_owner 不能成为任何角色的成员,并且它不能拥有非隐式成员。最初,此角色拥有 public 架构,因此每个数据库所有者都管理该架构的本地使用。

The pg_database_owner role has one implicit, situation-dependent member, namely the owner of the current database. Like any role, it can own objects or receive grants of access privileges. Consequently, once pg_database_owner has rights within a template database, each owner of a database instantiated from that template will exercise those rights. pg_database_owner cannot be a member of any role, and it cannot have non-implicit members. Initially, this role owns the public schema, so each database owner governs local use of the schema.

_pg_signal_backend_角色的目的是允许管理员启用受信但非超级用户的角色发送信号到其他后端。此角色当前可以发送信号以取消另一个后端上的查询或终止其会话。然而,授予此角色的用户无法将信号发送到超级用户拥有的后端。请参阅 Section 9.27.2

The pg_signal_backend role is intended to allow administrators to enable trusted, but non-superuser, roles to send signals to other backends. Currently this role enables sending of signals for canceling a query on another backend or terminating its session. A user granted this role cannot however send signals to a backend owned by a superuser. See Section 9.27.2.

pg_read_server_files, pg_write_server_filespg_execute_server_program 角色旨在让管理员拥有可信的(但不是超级用户)角色,这些角色能够像用户一样在数据库服务器上访问文件并运行程序(前提是数据库由该用户运行)。由于这些角色能够访问服务器文件系统上的任何文件,因此在直接访问文件时,它们绕过所有数据库级别的权限检查,并且可能会被用来获得超级用户级别的访问权限,因此在将这些角色授予用户时应格外小心。

The pg_read_server_files, pg_write_server_files and pg_execute_server_program roles are intended to allow administrators to have trusted, but non-superuser, roles which are able to access files and run programs on the database server as the user the database runs as. As these roles are able to access any file on the server file system, they bypass all database-level permission checks when accessing files directly and they could be used to gain superuser-level access, therefore great care should be taken when granting these roles to users.

在授予这些角色时应格外小心,以确保只在需要时使用它们,并了解这些角色授予对特权信息访问权限。

Care should be taken when granting these roles to ensure they are only used where needed and with the understanding that these roles grant access to privileged information.

管理员可以使用 GRANT 命令授予用户对这些角色的访问权限,例如:

Administrators can grant access to these roles to users using the GRANT command, for example:

GRANT pg_signal_backend TO admin_user;