Skip to content

ROLE

Grant membership in a role to one or more other roles.

Syntax

GRANT role_name [, ...] TO role_name [, ...] [ WITH ADMIN OPTION ]

Parameters

Membership propagates the privileges granted to a role to each of its members. WITH ADMIN OPTION means that the role can grant and revoke membership in the role to others. Database superusers can grant or revoke membership in any role to anyone.

Roles that have CREATEROLE privilege (as conferred with CREATE ROLE statements) can grant or revoke membership in any role that is not a superuser.

You cannot grant membership in a role to PUBLIC.

Examples

For example, grant membership to the allqa role for a newhire role:

premdb=# create role newhire;
CREATE ROLE
premdb=# grant allqa to newhire;
GRANT ROLE
premdb=# \du
                                   List of roles
  Role name  |                         Attributes                         | Member of 
-------------+------------------------------------------------------------+-----------
 ...
 allqa       | Create DB, Cannot login                                    | {}
 newhire     | Cannot login                                               | {allqa}
 ...

Parent topic:GRANT