Configure roles and privileges for PostgreSQL PGVector users
You can manage user access rights to databases in the PostgreSQL PGVector 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 PGVector 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 PGVector cluster cannot be changed. The superuser role is not provided.
Change the user's roles
You can change the list of roles for an existing user: grant additional roles or revoke previously granted ones.
-
In the Control Panel, in the top menu, click Products and select Managed Databases.
-
Open the Active tab.
-
Open the cluster page → Users tab.
-
In the user's menu, select Configure.
-
In the Roles field, click .
-
To change the user's roles, check or uncheck the boxes next to the roles.
-
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.
-
Connect to the database as the object owner.
-
Grant the necessary privileges to the user using the
GRANTcommand.Example of granting read access (
SELECT) to the tabletablefor the useruser: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.
-
Connect to the database as the object owner.
-
Revoke privileges from the user using the
REVOKEcommand.Example of revoking a privilege from user
useron schemaschema: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.
-
Create user
user. -
Grant access to the user
userfor the database. -
Connect to the database as the object owner.
-
Create schema
schemaand tabletable:CREATE SCHEMA schema;CREATE TABLE schema.table(i int);INSERT INTO schema.table(i) values(1); -
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;