SET ROLE v15
SET ROLE — Set the current user identifier of the current session.
This command sets the current user identifier of the current SQL session context to
SET ROLE, permissions checking for SQL commands is carried out as though the named role is the one that logged in originally.
The specified role name must be a role that the current session user is a member of. A superuser can select any role.
NONE resets the current user identifier to the current session user identifier. Any user can execute these forms.
You can use this command to add or restrict privileges. If the session user role has the
INHERITS attribute, then it automatically has all the privileges of every role that it can set the role to. In this case,
SET ROLE drops all the privileges assigned directly to the session user and to the other roles it is a member of, which leaves only the privileges available to the named role. If the session user role has the
SET ROLE drops the privileges assigned directly to the session user and instead acquires the privileges available to the named role. When a superuser chooses to set a role to a non-superuser role, they lose their superuser privileges.
mary takes on the identity of role
mary reverts back to their own identity: