{
    "mode": "man",
    "parameter": "SET_SESSION_AUTHORIZATION",
    "section": "7",
    "url": "https://www.chedong.com/phpMan.php/man/SET_SESSION_AUTHORIZATION/7/json",
    "generated": "2026-07-05T13:33:22Z",
    "synopsis": "SET [ SESSION | LOCAL ] SESSION AUTHORIZATION username\nSET [ SESSION | LOCAL ] SESSION AUTHORIZATION DEFAULT\nRESET SESSION AUTHORIZATION",
    "sections": {
        "NAME": {
            "content": "SETSESSIONAUTHORIZATION - set the session user identifier and the current user identifier\nof the current session\n",
            "subsections": []
        },
        "SYNOPSIS": {
            "content": "SET [ SESSION | LOCAL ] SESSION AUTHORIZATION username\nSET [ SESSION | LOCAL ] SESSION AUTHORIZATION DEFAULT\nRESET SESSION AUTHORIZATION\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "This command sets the session user identifier and the current user identifier of the current\nSQL session to be username. The user name can be written as either an identifier or a string\nliteral. Using this command, it is possible, for example, to temporarily become an\nunprivileged user and later switch back to being a superuser.\n\nThe session user identifier is initially set to be the (possibly authenticated) user name\nprovided by the client. The current user identifier is normally equal to the session user\nidentifier, but might change temporarily in the context of SECURITY DEFINER functions and\nsimilar mechanisms; it can also be changed by SET ROLE. The current user identifier is\nrelevant for permission checking.\n\nThe session user identifier can be changed only if the initial session user (the\nauthenticated user) had the superuser privilege. Otherwise, the command is accepted only if\nit specifies the authenticated user name.\n\nThe SESSION and LOCAL modifiers act the same as for the regular SET command.\n\nThe DEFAULT and RESET forms reset the session and current user identifiers to be the\noriginally authenticated user name. These forms can be executed by any user.\n",
            "subsections": []
        },
        "NOTES": {
            "content": "SET SESSION AUTHORIZATION cannot be used within a SECURITY DEFINER function.\n",
            "subsections": []
        },
        "EXAMPLES": {
            "content": "SELECT SESSIONUSER, CURRENTUSER;\n\nsessionuser | currentuser\n--------------+--------------\npeter        | peter\n\nSET SESSION AUTHORIZATION 'paul';\n\nSELECT SESSIONUSER, CURRENTUSER;\n\nsessionuser | currentuser\n--------------+--------------\npaul         | paul\n",
            "subsections": []
        },
        "COMPATIBILITY": {
            "content": "The SQL standard allows some other expressions to appear in place of the literal username,\nbut these options are not important in practice.  PostgreSQL allows identifier syntax\n(\"username\"), which SQL does not. SQL does not allow this command during a transaction;\nPostgreSQL does not make this restriction because there is no reason to. The SESSION and\nLOCAL modifiers are a PostgreSQL extension, as is the RESET syntax.\n\nThe privileges necessary to execute this command are left implementation-defined by the\nstandard.\n",
            "subsections": []
        },
        "SEE ALSO": {
            "content": "SET ROLE (SETROLE(7))\n\n\n\nPostgreSQL 14.23                                2026                    SET SESSION AUTHORIZATION(7)",
            "subsections": []
        }
    },
    "summary": "SETSESSIONAUTHORIZATION - set the session user identifier and the current user identifier of the current session",
    "flags": [],
    "examples": [
        "SELECT SESSIONUSER, CURRENTUSER;",
        "sessionuser | currentuser",
        "--------------+--------------",
        "peter        | peter",
        "SET SESSION AUTHORIZATION 'paul';",
        "SELECT SESSIONUSER, CURRENTUSER;",
        "sessionuser | currentuser",
        "--------------+--------------",
        "paul         | paul"
    ],
    "see_also": [
        {
            "name": "SETROLE",
            "section": "7",
            "url": "https://www.chedong.com/phpMan.php/man/SETROLE/7/json"
        },
        {
            "name": "AUTHORIZATION",
            "section": "7",
            "url": "https://www.chedong.com/phpMan.php/man/AUTHORIZATION/7/json"
        }
    ]
}