SET_SESSION_AUTHORIZATION(7pg14)
π SET_SESSION_AUTHORIZATION (7pg14)
okay so bestie, welcome to the glow-up page for SET_SESSION_AUTHORIZATION β straight out of the PostgreSQL 14.24 Documentation, no cap. This is the command that lets your current session switch up who it says it is. main character energy, but like, with permissions. β¨
π NAME π
SET_SESSION_AUTHORIZATION β the icon that sets the session user identifier and the current user identifier of the current session. two IDs, one command, slay. π
πΈ SYNOPSIS πΈ
SET [ SESSION | LOCAL ] SESSION AUTHORIZATION user_name
SET [ SESSION | LOCAL ] SESSION AUTHORIZATION DEFAULT
RESET SESSION AUTHORIZATION
look at her. three whole forms. she's flexible. π¦
π DESCRIPTION π
This command sets the session user identifier and the current user identifier of the current SQL session to be user_name. The user name can be written as either an identifier or a string literal. yes, both. she's not picky. π«
Using this command, it is possible β for example β to temporarily become an unprivileged user and later switch back to being a superuser. literally the costume change of the SQL world, iykyk. π§
The session user identifier is initially set to be the (possibly authenticated) user name provided by the client. The current user identifier is normally equal to the session user identifier, but might change temporarily in the context of SECURITY DEFINER functions and similar mechanisms; it can also be changed by SET ROLE. The current user identifier is relevant for permission checking. so likeβ¦ the current user is the one doing the actual permission-checking, periodt. π₯
The session user identifier can be changed only if the initial session user (the authenticated user) had the superuser privilege. Otherwise, the command is accepted only if it specifies the authenticated user name. that's the vibe check you cannot skip, bestie β no superuser, no identity theft. π
The SESSION and LOCAL modifiers act the same as for the regular SET command. same energy, different command. π«Ά
The DEFAULT and RESET forms reset the session and current user identifiers to be the originally authenticated user name. These forms can be executed by any user. so if you ever get lost, you can always come home. π
β NOTES β
π¨SET SESSION AUTHORIZATIONcannot be used within aSECURITY DEFINERfunction. like, it's giving "not allowed in there." respect the boundary. π
π EXAMPLES π
okay this is the part where she serves. watch. π
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
peter walked so paul could run. ate and left absolutely no crumbs. π
π COMPATIBILITY π
The SQL standard allows some other expressions to appear in place of the literal user_name, but these options are not important in practice. (read: nobody's using them, ngl.) π
PostgreSQL allows identifier syntax ("username"), which SQL does not. SQL does not allow this command during a transaction; PostgreSQL does not make this restriction because there is no reason to. fr fr β why gatekeep something for no reason. π€·ββοΈ
The SESSION and LOCAL modifiers are a PostgreSQL extension, as is the RESET syntax. homegrown excellence. π±
The privileges necessary to execute this command are left implementation-defined by the standard. so the standard was like "you figure it out" and dipped. π
π¦ SEE ALSO π¦
SET ROLE(SET_ROLE(7)) β her sister, also iconic, also worth a read π«Ά
and that's the page, bestie!! π no cap, you're now fully fluent in session identity shenanigans. this whole thing shipped with PostgreSQL 14.24, dated 2026 β so like, bookmark it, screenshot it, put it on your fridge. πβ¨π
π¦ where this page comes from
- opensuse-leap 16.0: postgresql14 14.24-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql14 14.24-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql14 14.24-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql14 14.24-160000.1.1 Β· PostgreSQL
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms