Role and user management
Greenplum® manages database access rights using two types of roles:
- User: Role that can log in to the database.
- Group: Role that includes other roles.
For more information, see Users and roles.
The admin user is created together with the Yandex MPP Analytics for PostgreSQL cluster and automatically gets the mdb_admin role. Connect to the database on its behalf to:
- View a list of roles.
- Create a role.
- Configure group roles.
- Change role attributes.
- Configure role privileges.
- Delete a role.
For more information about role interaction commands, see the Greenplum® documentation
View a list of roles
Run this command:
SELECT rolname FROM pg_roles;
To see a list of roles with their privileges, run the command:
SELECT
rolname,
rolsuper,
rolcreatedb,
rolcreaterole,
rolinherit,
rolcanlogin,
rolconnlimit,
rolcreaterextgpfd
FROM pg_roles;
Result:
rolname | rolsuper | rolcreatedb | rolcreaterole | rolinherit | rolcanlogin | rolconnlimit | rolcreaterextgpfd
----------------+----------+-------------+---------------+------------+-------------+--------------+-------------------
mdb_admin | f | f | f | t | f | -1 | f
gpadmin | t | t | t | t | t | -1 | t
monitor | t | f | f | t | t | -1 | f
user1 | f | t | t | t | t | -1 | t
Where:
- t: Privilege is available.
- f: No privilege.
Create a role
Run this command:
CREATE ROLE <role_name> <attribute_list>;
For a list of available attributes, see Attributes.
Configure group roles
To add a role to a group role, run the command:
GRANT <group_role_name> TO <list_of_roles_separated_by_commas>;
You can obtain role names with a list of roles in the cluster.
The LOGIN, SUPERUSER, CREATEDB, CREATEROLE, CREATEEXTTABLE, and RESOURCE QUEUE attributes are not inherited. To use all attributes of the group role, run the following command on behalf of the role:
SET ROLE <group_role_name>;
To remove a role from a group role, run the command:
REVOKE <group_role_name> FROM <list_of_roles_separated_by_commas>;
Change role attributes
Run this command:
ALTER ROLE <role_name> <attribute_list>;
For a list of available attributes, see Attributes.
Configure role privileges
To grant privileges to a role, run the command:
GRANT <list_of_privileges_separated_by_commas> ON <object_name> TO <role_name>;
For a list of available privileges, see Privileges.
To revoke privileges from a role, run the command:
REVOKE <list_of_privileges_separated_by_commas> ON <object_name> FROM <role_name>;
Instead of listing all the object's privileges, use ALL PRIVILEGES.
To revoke all privileges of all the role's objects, run the command:
DROP OWNED BY <role_name>;
Delete a role
Before deleting a role, delete all objects it owns or reassign their ownership rights and revoke all privileges for other objects.
Run this command:
DROP ROLE <role_name>;
Examples
Creating a role
Create a role with these test characteristics:
- Name:
greenplum_user. - Attributes:
CREATEDBandCREATEROLE. - Capable of logging in to the system using a secure password:
password123.
Run this command:
CREATE ROLE greenplum_user CREATEDB CREATEROLE LOGIN ENCRYPTED PASSWORD 'password123';
Check that the new role with the specified attributes appeared in the list:
SELECT
rolname,
rolsuper,
rolcreatedb,
rolcreaterole,
rolinherit,
rolcanlogin,
rolconnlimit,
rolcreaterextgpfd
FROM pg_roles;
Greenplum® and Greenplum Database® are registered trademarks or trademarks of Broadcom Inc. in the United States and/or other countries.