Granting Privileges to Roles
Superusers and owners of schemas, tables, and other database objects can assign privileges to a role, just as they can assign privileges to other users with GRANT statements. See Database Privileges for information about which privileges can be granted.
Granting a privilege to a role immediately affects active user sessions. When you grant a new privilege, it becomes immediately available to every user with the role active.
Example
The following example creates two roles and assigns them different privileges on a single table called applog.
-
Create a table called applog:
=> CREATE TABLE applog (id int, sourceID VARCHAR(32), data TIMESTAMP, event VARCHAR(256));
-
Create a new role called logreader:
=> CREATE ROLE logreader;
-
Assign read-only privileges to the logreader role on table applog:
=> GRANT SELECT ON applog TO logreader; -
Create a role called logwriter:
=> CREATE ROLE logwriter;
-
Assign write privileges to the logwriter role on table applog:
=> GRANT INSERT ON applog TO logwriter;