1SET SESSION AUTHORIZATION(P7o)stgreSQL 12.2 DocumentatSiEoTnSESSION AUTHORIZATION(7)
2
3
4
6 SET_SESSION_AUTHORIZATION - set the session user identifier and the
7 current user identifier of the current session
8
10 SET [ SESSION | LOCAL ] SESSION AUTHORIZATION user_name
11 SET [ SESSION | LOCAL ] SESSION AUTHORIZATION DEFAULT
12 RESET SESSION AUTHORIZATION
13
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.
20
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 (SET_ROLE(7)).
26 The current user identifier is relevant for permission checking.
27
28 The session user identifier can be changed only if the initial session
29 user (the authenticated user) had the superuser privilege. Otherwise,
30 the command is accepted only if it specifies the authenticated user
31 name.
32
33 The SESSION and LOCAL modifiers act the same as for the regular SET(7)
34 command.
35
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.
39
41 SET SESSION AUTHORIZATION cannot be used within a SECURITY DEFINER
42 function.
43
45 SELECT SESSION_USER, CURRENT_USER;
46
47 session_user | current_user
48 --------------+--------------
49 peter | peter
50
51 SET SESSION AUTHORIZATION 'paul';
52
53 SELECT SESSION_USER, CURRENT_USER;
54
55 session_user | current_user
56 --------------+--------------
57 paul | paul
58
60 The SQL standard allows some other expressions to appear in place of
61 the literal user_name, but these options are not important in practice.
62 PostgreSQL allows identifier syntax ("username"), which SQL does not.
63 SQL does not allow this command during a transaction; PostgreSQL does
64 not make this restriction because there is no reason to. The SESSION
65 and LOCAL modifiers are a PostgreSQL extension, as is the RESET syntax.
66
67 The privileges necessary to execute this command are left
68 implementation-defined by the standard.
69
71 SET ROLE (SET_ROLE(7))
72
73
74
75PostgreSQL 12.2 2020 SET SESSION AUTHORIZATION(7)