Skip to main content
Version: 1.0.16

SET SESSION AUTHORIZATION

SET SESSION AUTHORIZATION — Set the session user identifier and the current user identifier of the current session

Synopsis

SET [ SESSION | LOCAL ] SESSION AUTHORIZATION user_name

SET [ SESSION | LOCAL ] SESSION AUTHORIZATION DEFAULT

RESET SESSION AUTHORIZATION

Description

This command sets the session user identifier and the current user identifier of the current SQL session to user_name. The user name can be written as an identifier or a string. For example, this command can be used to temporarily become an unprivileged user and later switch back to being a superuser.

The session user identifier is initially set to the (possibly authenticated) user name provided by the client. The current user identifier is normally equal to the session user identifier, but may change temporarily in contexts such as SECURITY DEFINER functions and similar mechanisms. It can also be changed with SET ROLE. The current user identifier is relevant for privilege checking.

The session user identifier can only be changed if the initial session user (the authenticated user) has superuser privileges. Otherwise, the command is only accepted if it specifies the authenticated user name.

The SESSION and LOCAL modifiers function the same as for the regular SET command.

The DEFAULT and RESET forms reset the session user identifier and current user identifier to the original authenticated user name. These forms can be executed by any user.

Notes

SET SESSION AUTHORIZATION cannot be used inside a SECURITY DEFINER function.

Examples

SELECT SESSION_USER, CURRENT_USER;

session_user | current_user

--------------+--------------

peter | peter

SET SESSION AUTHORIZATION 'paul';

SELECT SESSION_USER, CURRENT_USER;

session_user | current_user

--------------+--------------

paul | paul

See Also

SET ROLE