Skip to main content

Configure roles and privileges for PostgreSQL TimescaleDB users

You can manage user access rights to databases in the PostgreSQL TimescaleDB cluster using roles and privileges.

A role is a predefined set of privileges. Roles are configured via the Control Panel.

A privilege is the right to perform operations on a specific database object, such as a schema, table, or function. Privileges are configured using the GRANT and REVOKE SQL commands.

Roles assigned to a user apply to all databases in the cluster, whereas privileges apply only to the specific database where they are granted.

Roles and privileges are independent access management mechanisms. You can use them separately or together. Assigning roles does not override user privileges configured with the GRANT and REVOKE commands.

Roles

Users of the PostgreSQL TimescaleDB cluster can be assigned predefined roles. Custom roles cannot be created.

Each user can be assigned multiple roles simultaneously.

You can assign roles when creating a user, as well as change the list of roles for an existing user by granting additional roles or revoking previously granted ones.

Predefined roles

The set of predefined roles in the PostgreSQL TimescaleDB cluster cannot be changed. The superuser role is not provided.

RoleDescription
dbaas_adminProvides rights:

  • to use subscriptions for logical replication;
  • to use the privileges of a predefined role pg_monitor. For more information about predefined roles, see the instructions Predefined Roles PostgreSQL documentation;
  • use of extensions, which require the role dbaas_admin;
  • use of statistics reset functions from the extension pg_stat_statements
dbaas_replicationGrants privileges:

pg_read_all_statsProvides access to PostgreSQL performance statistics, including information from system monitoring and statistics views. This role is intended for diagnostics and monitoring and does not grant privileges to modify user data
pg_signal_backendAllows sending signals to other PostgreSQL server processes, such as terminating or canceling user sessions. This role does not allow managing superuser processes and does not provide access to user data

Change the user's roles

You can change the list of roles for an existing user: grant additional roles or revoke previously granted ones.

  1. In the Control Panel, in the top menu, click Products and select Managed Databases.

  2. Open the Active tab.

  3. Open the cluster page → Users tab.

  4. In the user's menu, select Configure.

  5. In the Roles field, click .

  6. To change the user's roles, check or uncheck the boxes next to the roles.

  7. To save your changes, click .

Privileges

A database object (schema, table, function) is created by a specific user, who becomes the owner of the object and has all rights to it by default. Other users, including the database owner, can be granted privileges on the object.

Starting with PostgreSQL 15, the CREATE privilege on the public schema is no longer granted by default. Options for working with the public schema are described in the Usage Patterns section of the PostgreSQL documentation Schemas guide.

Grant privileges

You can grant users privileges on database objects using the GRANT command. For more details, see the GRANT section in the PostgreSQL documentation.

  1. Connect to the database as the object owner.

  2. Grant the necessary privileges to the user using the GRANT command.

    Example of granting read access (SELECT) to the table table for the user user:

    GRANT SELECT ON table TO user;

Revoke privileges

You can revoke privileges from a user using the REVOKE command; read more in the REVOKE PostgreSQL documentation.

  1. Connect to the database as the object owner.

  2. Revoke privileges from the user using the REVOKE command.

    Example of revoking a privilege from user user on schema schema:

    REVOKE USAGE ON SCHEMA schema FROM user;

Example of creating a schema user with read-only rights

You can create a user with access to the cluster database, a table in the default schema, and all tables in the schema.

Automatically all new tables will be created with read-only access (read-only) for this user.

  1. Create user user.

  2. Grant access to the user user for the database.

  3. Connect to the database as the object owner.

  4. Create schema schema and table table:

    CREATE SCHEMA schema;
    CREATE TABLE schema.table(i int);
    INSERT INTO schema.table(i) values(1);
  5. Grant privileges to user user:

    GRANT USAGE ON SCHEMA schema TO user;
    GRANT SELECT ON ALL TABLES IN SCHEMA schema TO user;
    ALTER DEFAULT PRIVILEGES IN SCHEMA schema GRANT SELECT ON TABLES TO user;