1SET ROLE(7)             PostgreSQL 9.2.24 Documentation            SET ROLE(7)
2
3
4

NAME

6       SET_ROLE - set the current user identifier of the current session
7

SYNOPSIS

9       SET [ SESSION | LOCAL ] ROLE role_name
10       SET [ SESSION | LOCAL ] ROLE NONE
11       RESET ROLE
12

DESCRIPTION

14       This command sets the current user identifier of the current SQL
15       session to be role_name. The role name can be written as either an
16       identifier or a string literal. After SET ROLE, permissions checking
17       for SQL commands is carried out as though the named role were the one
18       that had logged in originally.
19
20       The specified role_name must be a role that the current session user is
21       a member of. (If the session user is a superuser, any role can be
22       selected.)
23
24       The SESSION and LOCAL modifiers act the same as for the regular SET(7)
25       command.
26
27       The NONE and RESET forms reset the current user identifier to be the
28       current session user identifier. These forms can be executed by any
29       user.
30

NOTES

32       Using this command, it is possible to either add privileges or restrict
33       one's privileges. If the session user role has the INHERITS attribute,
34       then it automatically has all the privileges of every role that it
35       could SET ROLE to; in this case SET ROLE effectively drops all the
36       privileges assigned directly to the session user and to the other roles
37       it is a member of, leaving only the privileges available to the named
38       role. On the other hand, if the session user role has the NOINHERITS
39       attribute, SET ROLE drops the privileges assigned directly to the
40       session user and instead acquires the privileges available to the named
41       role.
42
43       In particular, when a superuser chooses to SET ROLE to a non-superuser
44       role, she loses her superuser privileges.
45
46       SET ROLE has effects comparable to SET SESSION AUTHORIZATION
47       (SET_SESSION_AUTHORIZATION(7)), but the privilege checks involved are
48       quite different. Also, SET SESSION AUTHORIZATION determines which roles
49       are allowable for later SET ROLE commands, whereas changing roles with
50       SET ROLE does not change the set of roles allowed to a later SET ROLE.
51
52       SET ROLE does not process session variables as specified by the role's
53       ALTER ROLE (ALTER_ROLE(7)) settings; this only happens during login.
54
55       SET ROLE cannot be used within a SECURITY DEFINER function.
56

EXAMPLES

58           SELECT SESSION_USER, CURRENT_USER;
59
60            session_user | current_user
61           --------------+--------------
62            peter        | peter
63
64           SET ROLE 'paul';
65
66           SELECT SESSION_USER, CURRENT_USER;
67
68            session_user | current_user
69           --------------+--------------
70            peter        | paul
71

COMPATIBILITY

73       PostgreSQL allows identifier syntax ("rolename"), while the SQL
74       standard requires the role name to be written as a string literal. SQL
75       does not allow this command during a transaction; PostgreSQL does not
76       make this restriction because there is no reason to. The SESSION and
77       LOCAL modifiers are a PostgreSQL extension, as is the RESET syntax.
78

SEE ALSO

80       SET SESSION AUTHORIZATION (SET_SESSION_AUTHORIZATION(7))
81
82
83
84PostgreSQL 9.2.24                 2017-11-06                       SET ROLE(7)
Impressum