SET SESSION AUTHORIZATION
Sets the current and session user for the current database connection. You can change session authorization to execute queries as another user for testing or debugging purposes, or to limit query access.
Syntax
SET SESSION AUTHORIZATION { username | DEFAULT }
Parameters
username
- The name of the user that you want to authorize for the current SQL session.
DEFAULT
- Sets session authorization to the dbadmin user.
Privileges
Superuser
Examples
In the following example, the dbadmin
gives the debuguser
user session authorization, and then changes the session authorization back to the dbadmin
user.
-
Verify the current user and session user:
=> SELECT CURRENT_USER(), SESSION_USER(); current_user | session_user --------------+-------------- dbadmin | dbadmin (1 row)
-
Set authorization for the current session to
debuguser
, and verify the changes:=> SET SESSION AUTHORIZATION debuguser; SET => SELECT CURRENT_USER(), SESSION_USER(); current_user | session_user --------------+-------------- debuguser | debuguser (1 row)
-
After you complete debugging tasks, set the session authorization to
DEFAULT
to set the current and session user back todbadmin
user, and verify the changes:=> SET SESSION AUTHORIZATION DEFAULT; SET => SELECT CURRENT_USER(), SESSION_USER(); current_user | session_user --------------+-------------- dbadmin | dbadmin (1 row)