2 SET SESSION AUTHORIZATION
4 SET SESSION AUTHORIZATION — set the session user identifier and the
5 current user identifier of the current session
9 SET [ SESSION | LOCAL ] SESSION AUTHORIZATION user_name
10 SET [ SESSION | LOCAL ] SESSION AUTHORIZATION DEFAULT
11 RESET SESSION AUTHORIZATION
15 This command sets the session user identifier and the current user
16 identifier of the current SQL session to be user_name. The user name
17 can be written as either an identifier or a string literal. Using this
18 command, it is possible, for example, to temporarily become an
19 unprivileged user and later switch back to being a superuser.
21 The session user identifier is initially set to be the (possibly
22 authenticated) user name provided by the client. The current user
23 identifier is normally equal to the session user identifier, but might
24 change temporarily in the context of SECURITY DEFINER functions and
25 similar mechanisms; it can also be changed by SET ROLE. The current
26 user identifier is relevant for permission checking.
28 The session user identifier can be changed only if the initial session
29 user (the authenticated user) has the superuser privilege. Otherwise,
30 the command is accepted only if it specifies the authenticated user
33 The SESSION and LOCAL modifiers act the same as for the regular SET
36 The DEFAULT and RESET forms reset the session and current user
37 identifiers to be the originally authenticated user name. These forms
38 can be executed by any user.
42 SET SESSION AUTHORIZATION cannot be used within a SECURITY DEFINER
47 SELECT SESSION_USER, CURRENT_USER;
49 session_user | current_user
50 --------------+--------------
53 SET SESSION AUTHORIZATION 'paul';
55 SELECT SESSION_USER, CURRENT_USER;
57 session_user | current_user
58 --------------+--------------
63 The SQL standard allows some other expressions to appear in place of
64 the literal user_name, but these options are not important in practice.
65 PostgreSQL allows identifier syntax ("username"), which SQL does not.
66 SQL does not allow this command during a transaction; PostgreSQL does
67 not make this restriction because there is no reason to. The SESSION
68 and LOCAL modifiers are a PostgreSQL extension, as is the RESET syntax.
70 The privileges necessary to execute this command are left
71 implementation-defined by the standard.