Skip to content

SET ROLE

Set the current user for the current session.

SET [ SESSION | LOCAL ] ROLE role_name
SET [ SESSION | LOCAL ] ROLE NONE
RESET ROLE

After this command is run, permissions checking for subsequent SQL commands is applied based on the privileges of the named role. The role_name must be a role that the current session user is a member of. If the session user is a superuser, any role can be specified.

LOCAL can only be specified within a transaction.

NONE and RESET reset the current user to the current session user. Any user can run these forms of the command.

For example:

premdb=# select session_user, current_user;
 session_user | current_user 
--------------+--------------
 brumsby      | brumsby
(1 row)

premdb=# set role bobr;
SET
premdb=> select session_user, current_user;
 session_user | current_user 
--------------+--------------
 brumsby      | bobr
(1 row)

Parent topic:SQL Commands