{
    "mode": "man",
    "parameter": "ALTER_ROLE",
    "section": "7",
    "url": "https://www.chedong.com/phpMan.php/man/ALTER_ROLE/7/json",
    "generated": "2026-10-08T03:19:58Z",
    "synopsis": "ALTER ROLE rolespecification [ WITH ] option [ ... ]\nwhere option can be:\nSUPERUSER | NOSUPERUSER\n| CREATEDB | NOCREATEDB\n| CREATEROLE | NOCREATEROLE\n| INHERIT | NOINHERIT\n| LOGIN | NOLOGIN\n| REPLICATION | NOREPLICATION\n| BYPASSRLS | NOBYPASSRLS\n| CONNECTION LIMIT connlimit\n| [ ENCRYPTED ] PASSWORD 'password' | PASSWORD NULL\n| VALID UNTIL 'timestamp'\nALTER ROLE name RENAME TO newname\nALTER ROLE { rolespecification | ALL } [ IN DATABASE databasename ] SET configurationparameter { TO | = } { value | DEFAULT }\nALTER ROLE { rolespecification | ALL } [ IN DATABASE databasename ] SET configurationparameter FROM CURRENT\nALTER ROLE { rolespecification | ALL } [ IN DATABASE databasename ] RESET configurationparameter\nALTER ROLE { rolespecification | ALL } [ IN DATABASE databasename ] RESET ALL\nwhere rolespecification can be:\nrolename\n| CURRENTROLE\n| CURRENTUSER\n| SESSIONUSER",
    "sections": {
        "NAME": {
            "content": "ALTERROLE - change a database role\n",
            "subsections": []
        },
        "SYNOPSIS": {
            "content": "ALTER ROLE rolespecification [ WITH ] option [ ... ]\n\nwhere option can be:\n\nSUPERUSER | NOSUPERUSER\n| CREATEDB | NOCREATEDB\n| CREATEROLE | NOCREATEROLE\n| INHERIT | NOINHERIT\n| LOGIN | NOLOGIN\n| REPLICATION | NOREPLICATION\n| BYPASSRLS | NOBYPASSRLS\n| CONNECTION LIMIT connlimit\n| [ ENCRYPTED ] PASSWORD 'password' | PASSWORD NULL\n| VALID UNTIL 'timestamp'\n\nALTER ROLE name RENAME TO newname\n\nALTER ROLE { rolespecification | ALL } [ IN DATABASE databasename ] SET configurationparameter { TO | = } { value | DEFAULT }\nALTER ROLE { rolespecification | ALL } [ IN DATABASE databasename ] SET configurationparameter FROM CURRENT\nALTER ROLE { rolespecification | ALL } [ IN DATABASE databasename ] RESET configurationparameter\nALTER ROLE { rolespecification | ALL } [ IN DATABASE databasename ] RESET ALL\n\nwhere rolespecification can be:\n\nrolename\n| CURRENTROLE\n| CURRENTUSER\n| SESSIONUSER\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "ALTER ROLE changes the attributes of a PostgreSQL role.\n\nThe first variant of this command listed in the synopsis can change many of the role\nattributes that can be specified in CREATE ROLE. (All the possible attributes are covered,\nexcept that there are no options for adding or removing memberships; use GRANT and REVOKE for\nthat.) Attributes not mentioned in the command retain their previous settings. Database\nsuperusers can change any of these settings for any role. Non-superuser roles having\nCREATEROLE privilege can change most of these properties, but only for non-superuser and\nnon-replication roles for which they have been granted ADMIN OPTION. Non-superusers cannot\nchange the SUPERUSER property and can change the CREATEDB, REPLICATION, and BYPASSRLS\nproperties only if they possess the corresponding property themselves. Ordinary roles can\nonly change their own password.\n\nThe second variant changes the name of the role. Database superusers can rename any role.\nRoles having CREATEROLE privilege can rename non-superuser roles for which they have been\ngranted ADMIN OPTION. The current session user cannot be renamed. (Connect as a different\nuser if you need to do that.) Because MD5-encrypted passwords use the role name as\ncryptographic salt, renaming a role clears its password if the password is MD5-encrypted.\n\nThe remaining variants change a role's session default for a configuration variable, either\nfor all databases or, when the IN DATABASE clause is specified, only for sessions in the\nnamed database. If ALL is specified instead of a role name, this changes the setting for all\nroles. Using ALL with IN DATABASE is effectively the same as using the command ALTER DATABASE\n... SET ....\n\nWhenever the role subsequently starts a new session, the specified value becomes the session\ndefault, overriding whatever setting is present in postgresql.conf or has been received from\nthe postgres command line. This only happens at login time; executing SET ROLE or SET SESSION\nAUTHORIZATION does not cause new configuration values to be set. Settings set for all\ndatabases are overridden by database-specific settings attached to a role. Settings for\nspecific databases or specific roles override settings for all roles.\n\nSuperusers can change anyone's session defaults. Roles having CREATEROLE privilege can change\ndefaults for non-superuser roles for which they have been granted ADMIN OPTION. Ordinary\nroles can only set defaults for themselves. Certain configuration variables cannot be set\nthis way, or can only be set if a superuser issues the command. Only superusers can change a\nsetting for all roles in all databases.\n",
            "subsections": []
        },
        "PARAMETERS": {
            "content": "name\nThe name of the role whose attributes are to be altered.\n\nCURRENTROLE\nCURRENTUSER\nAlter the current user instead of an explicitly identified role.\n\nSESSIONUSER\nAlter the current session user instead of an explicitly identified role.\n\nSUPERUSER\nNOSUPERUSER\nCREATEDB\nNOCREATEDB\nCREATEROLE\nNOCREATEROLE\nINHERIT\nNOINHERIT\nLOGIN\nNOLOGIN\nREPLICATION\nNOREPLICATION\nBYPASSRLS\nNOBYPASSRLS\nCONNECTION LIMIT connlimit\n[ ENCRYPTED ] PASSWORD 'password'\nPASSWORD NULL\nVALID UNTIL 'timestamp'\nThese clauses alter attributes originally set by CREATE ROLE. For more information, see\nthe CREATE ROLE reference page.\n\nnewname\nThe new name of the role.\n\ndatabasename\nThe name of the database the configuration variable should be set in.\n\nconfigurationparameter\nvalue\nSet this role's session default for the specified configuration parameter to the given\nvalue. If value is DEFAULT or, equivalently, RESET is used, the role-specific variable\nsetting is removed, so the role will inherit the system-wide default setting in new\nsessions. Use RESET ALL to clear all role-specific settings.  SET FROM CURRENT saves the\nsession's current value of the parameter as the role-specific value. If IN DATABASE is\nspecified, the configuration parameter is set or removed for the given role and database\nonly.\n\nRole-specific variable settings take effect only at login; SET ROLE and SET SESSION\nAUTHORIZATION do not process role-specific variable settings.\n\nSee SET(7) and Chapter 20 for more information about allowed parameter names and values.\n",
            "subsections": []
        },
        "NOTES": {
            "content": "Use CREATE ROLE to add new roles, and DROP ROLE to remove a role.\n\nALTER ROLE cannot change a role's memberships. Use GRANT and REVOKE to do that.\n\nCaution must be exercised when specifying an unencrypted password with this command. The\npassword will be transmitted to the server in cleartext, and it might also be logged in the\nclient's command history or the server log.  psql(1) contains a command \\password that can be\nused to change a role's password without exposing the cleartext password.\n\nIt is also possible to tie a session default to a specific database rather than to a role;\nsee ALTER DATABASE (ALTERDATABASE(7)). If there is a conflict, database-role-specific\nsettings override role-specific ones, which in turn override database-specific ones.\n",
            "subsections": []
        },
        "EXAMPLES": {
            "content": "Change a role's password:\n\nALTER ROLE davide WITH PASSWORD 'hu8jmn3';\n\nRemove a role's password:\n\nALTER ROLE davide WITH PASSWORD NULL;\n\nChange a password expiration date, specifying that the password should expire at midday on\n4th May 2015 using the time zone which is one hour ahead of UTC:\n\nALTER ROLE chris VALID UNTIL 'May 4 12:00:00 2015 +1';\n\nMake a password valid forever:\n\nALTER ROLE fred VALID UNTIL 'infinity';\n\nGive a role the ability to manage other roles and create new databases:\n\nALTER ROLE miriam CREATEROLE CREATEDB;\n\nGive a role a non-default setting of the maintenanceworkmem parameter:\n\nALTER ROLE workerbee SET maintenanceworkmem = 100000;\n\nGive a role a non-default, database-specific setting of the clientminmessages parameter:\n\nALTER ROLE fred IN DATABASE devel SET clientminmessages = DEBUG;\n",
            "subsections": []
        },
        "COMPATIBILITY": {
            "content": "The ALTER ROLE statement is a PostgreSQL extension.\n",
            "subsections": []
        },
        "SEE ALSO": {
            "content": "CREATE ROLE (CREATEROLE(7)), DROP ROLE (DROPROLE(7)), ALTER DATABASE (ALTERDATABASE(7)),\nSET(7)\n\nPostgreSQL 16.14                                2026                                   ALTER ROLE(7)",
            "subsections": []
        }
    },
    "summary": "ALTERROLE - change a database role",
    "flags": [],
    "examples": [
        "Change a role's password:",
        "ALTER ROLE davide WITH PASSWORD 'hu8jmn3';",
        "Remove a role's password:",
        "ALTER ROLE davide WITH PASSWORD NULL;",
        "Change a password expiration date, specifying that the password should expire at midday on",
        "4th May 2015 using the time zone which is one hour ahead of UTC:",
        "ALTER ROLE chris VALID UNTIL 'May 4 12:00:00 2015 +1';",
        "Make a password valid forever:",
        "ALTER ROLE fred VALID UNTIL 'infinity';",
        "Give a role the ability to manage other roles and create new databases:",
        "ALTER ROLE miriam CREATEROLE CREATEDB;",
        "Give a role a non-default setting of the maintenanceworkmem parameter:",
        "ALTER ROLE workerbee SET maintenanceworkmem = 100000;",
        "Give a role a non-default, database-specific setting of the clientminmessages parameter:",
        "ALTER ROLE fred IN DATABASE devel SET clientminmessages = DEBUG;"
    ],
    "see_also": [
        {
            "name": "CREATEROLE",
            "section": "7",
            "url": "https://www.chedong.com/phpMan.php/man/CREATEROLE/7/json"
        },
        {
            "name": "DROPROLE",
            "section": "7",
            "url": "https://www.chedong.com/phpMan.php/man/DROPROLE/7/json"
        },
        {
            "name": "ALTERDATABASE",
            "section": "7",
            "url": "https://www.chedong.com/phpMan.php/man/ALTERDATABASE/7/json"
        },
        {
            "name": "SET",
            "section": "7",
            "url": "https://www.chedong.com/phpMan.php/man/SET/7/json"
        },
        {
            "name": "ROLE",
            "section": "7",
            "url": "https://www.chedong.com/phpMan.php/man/ROLE/7/json"
        }
    ]
}