{
    "content": [
        {
            "type": "text",
            "text": "# SET_ROLE (man)\n\n## NAME\n\nSETROLE - set the current user identifier of the current session\n\n## SYNOPSIS\n\nSET [ SESSION | LOCAL ] ROLE rolename\nSET [ SESSION | LOCAL ] ROLE NONE\nRESET ROLE\n\n## DESCRIPTION\n\nThis command sets the current user identifier of the current SQL session to be rolename. The\nrole name can be written as either an identifier or a string literal. After SET ROLE,\npermissions checking for SQL commands is carried out as though the named role were the one\nthat had logged in originally.\n\n## Sections\n\n- **NAME**\n- **SYNOPSIS**\n- **DESCRIPTION**\n- **NOTES**\n- **EXAMPLES**\n- **COMPATIBILITY**\n- **SEE ALSO**\n\nUse structuredContent.sections for detailed options, examples, and full documentation.\n"
        }
    ],
    "structuredContent": {
        "command": "SET_ROLE",
        "section": "",
        "mode": "man",
        "summary": "SETROLE - set the current user identifier of the current session",
        "synopsis": "SET [ SESSION | LOCAL ] ROLE rolename\nSET [ SESSION | LOCAL ] ROLE NONE\nRESET ROLE",
        "tldr_summary": null,
        "tldr_examples": [],
        "tldr_source": null,
        "flags": [],
        "examples": [
            "SELECT SESSIONUSER, CURRENTUSER;",
            "sessionuser | currentuser",
            "--------------+--------------",
            "peter        | peter",
            "SET ROLE 'paul';",
            "SELECT SESSIONUSER, CURRENTUSER;",
            "sessionuser | currentuser",
            "--------------+--------------",
            "peter        | paul"
        ],
        "see_also": [
            {
                "name": "SETSESSIONAUTHORIZATION",
                "section": "7",
                "url": "https://www.chedong.com/phpMan.php/man/SETSESSIONAUTHORIZATION/7/json"
            },
            {
                "name": "ROLE",
                "section": "7",
                "url": "https://www.chedong.com/phpMan.php/man/ROLE/7/json"
            }
        ],
        "section_outline": [
            {
                "name": "NAME",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "SYNOPSIS",
                "lines": 4,
                "subsections": []
            },
            {
                "name": "DESCRIPTION",
                "lines": 16,
                "subsections": []
            },
            {
                "name": "NOTES",
                "lines": 21,
                "subsections": []
            },
            {
                "name": "EXAMPLES",
                "lines": 14,
                "subsections": []
            },
            {
                "name": "COMPATIBILITY",
                "lines": 5,
                "subsections": []
            },
            {
                "name": "SEE ALSO",
                "lines": 5,
                "subsections": []
            }
        ],
        "sections": {
            "NAME": {
                "content": "SETROLE - set the current user identifier of the current session\n",
                "subsections": []
            },
            "SYNOPSIS": {
                "content": "SET [ SESSION | LOCAL ] ROLE rolename\nSET [ SESSION | LOCAL ] ROLE NONE\nRESET ROLE\n",
                "subsections": []
            },
            "DESCRIPTION": {
                "content": "This command sets the current user identifier of the current SQL session to be rolename. The\nrole name can be written as either an identifier or a string literal. After SET ROLE,\npermissions checking for SQL commands is carried out as though the named role were the one\nthat had logged in originally.\n\nThe specified rolename must be a role that the current session user is a member of. (If the\nsession user is a superuser, any role can be selected.)\n\nThe SESSION and LOCAL modifiers act the same as for the regular SET command.\n\nSET ROLE NONE sets the current user identifier to the current session user identifier, as\nreturned by sessionuser.  RESET ROLE sets the current user identifier to the connection-time\nsetting specified by the command-line options, ALTER ROLE, or ALTER DATABASE, if any such\nsettings exist. Otherwise, RESET ROLE sets the current user identifier to the current session\nuser identifier. These forms can be executed by any user.\n",
                "subsections": []
            },
            "NOTES": {
                "content": "Using this command, it is possible to either add privileges or restrict one's privileges. If\nthe session user role has the INHERIT attribute, then it automatically has all the privileges\nof every role that it could SET ROLE to; in this case SET ROLE effectively drops all the\nprivileges assigned directly to the session user and to the other roles it is a member of,\nleaving only the privileges available to the named role. On the other hand, if the session\nuser role has the NOINHERIT attribute, SET ROLE drops the privileges assigned directly to the\nsession user and instead acquires the privileges available to the named role.\n\nIn particular, when a superuser chooses to SET ROLE to a non-superuser role, they lose their\nsuperuser privileges.\n\nSET ROLE has effects comparable to SET SESSION AUTHORIZATION, but the privilege checks\ninvolved are quite different. Also, SET SESSION AUTHORIZATION determines which roles are\nallowable for later SET ROLE commands, whereas changing roles with SET ROLE does not change\nthe set of roles allowed to a later SET ROLE.\n\nSET ROLE does not process session variables as specified by the role's ALTER ROLE settings;\nthis only happens during login.\n\nSET ROLE cannot be used within a SECURITY DEFINER function.\n",
                "subsections": []
            },
            "EXAMPLES": {
                "content": "SELECT SESSIONUSER, CURRENTUSER;\n\nsessionuser | currentuser\n--------------+--------------\npeter        | peter\n\nSET ROLE 'paul';\n\nSELECT SESSIONUSER, CURRENTUSER;\n\nsessionuser | currentuser\n--------------+--------------\npeter        | paul\n",
                "subsections": []
            },
            "COMPATIBILITY": {
                "content": "PostgreSQL allows identifier syntax (\"rolename\"), while the SQL standard requires the role\nname to be written as a string literal. 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",
                "subsections": []
            },
            "SEE ALSO": {
                "content": "SET SESSION AUTHORIZATION (SETSESSIONAUTHORIZATION(7))\n\n\n\nPostgreSQL 14.23                                2026                                     SET ROLE(7)",
                "subsections": []
            }
        }
    }
}