ALTER_ROLE(7pg14)
β¨ ALTER_ROLE(7) β¨ β change a database role
okay bestie, welcome to the glow-up zone for PostgreSQL roles π
this is the ALTER ROLE page from the PostgreSQL 14.24 Documentation, and we're gonna make it make sense fr fr.
πΈ NAME πΈ
ALTER_ROLE β change a database role
π SYNOPSIS π
ALTER ROLE role_specification [ WITH ] option [ ... ]
where option can be:
SUPERUSER | NOSUPERUSER
| CREATEDB | NOCREATEDB
| CREATEROLE | NOCREATEROLE
| INHERIT | NOINHERIT
| LOGIN | NOLOGIN
| REPLICATION | NOREPLICATION
| BYPASSRLS | NOBYPASSRLS
| CONNECTION LIMIT connlimit
| [ ENCRYPTED ] PASSWORD 'password' | PASSWORD NULL
| VALID UNTIL 'timestamp'
ALTER ROLE name RENAME TO new_name
ALTER ROLE { role_specification | ALL } [ IN DATABASE database_name ] SET configuration_parameter { TO | = } { value | DEFAULT }
ALTER ROLE { role_specification | ALL } [ IN DATABASE database_name ] SET configuration_parameter FROM CURRENT
ALTER ROLE { role_specification | ALL } [ IN DATABASE database_name ] RESET configuration_parameter
ALTER ROLE { role_specification | ALL } [ IN DATABASE database_name ] RESET ALL
where role_specification can be:
role_name
| CURRENT_ROLE
| CURRENT_USER
| SESSION_USER
π¦ DESCRIPTION π¦
so like, ALTER ROLE changes the attributes of a PostgreSQL role. periodt. π
The first variant in the synopsis (the one with all the options) can change many of the role attributes that you can also set in CREATE ROLE. (All the possible attributes are covered, except there are no options for adding or removing memberships β for that you gotta use GRANT and REVOKE.) Any attribute you don't mention in the command just keeps its previous setting, no cap.
Here's the permission tea β:
- Database superusers can change any of these settings for any role.
- Roles having
CREATEROLEprivilege can change any of these settings exceptSUPERUSER,REPLICATION, andBYPASSRLSβ and only for non-superuser and non-replication roles. - Ordinary roles can only change their own password. that's it, that's the whole vibe π.
The second variant changes the name of the role. Database superusers can rename any role. Roles having CREATEROLE privilege can rename non-superuser roles. The current session user cannot be renamed β connect as a different user if you need to do that, bestie. Also important: because MD5-encrypted passwords use the role name as cryptographic salt, renaming a role clears its password if the password is MD5-encrypted. π
The remaining variants change a role's session default for a configuration variable β either for all databases, or when the IN DATABASE clause is specified, only for sessions in the named database. If ALL is specified instead of a role name, this changes the setting for all roles. Using ALL with IN DATABASE is effectively the same as using the command ALTER DATABASE ... SET ....
Whenever the role subsequently starts a new session, the specified value becomes the session default, overriding whatever setting is present in postgresql.conf or has been received from the postgres command line. This only happens at login time β executing SET ROLE or SET SESSION AUTHORIZATION does not cause new configuration values to be set. Settings set for all databases are overridden by database-specific settings attached to a role. Settings for specific databases or specific roles override settings for all roles.
Superusers can change anyone's session defaults. Roles having CREATEROLE privilege can change defaults for non-superuser roles. Ordinary roles can only set defaults for themselves. Certain configuration variables cannot be set this way, or can only be set if a superuser issues the command. Only superusers can change a setting for all roles in all databases. π
π PARAMETERS π
nameβ the name of the role whose attributes are to be altered.CURRENT_ROLEβ alter the current user instead of an explicitly identified role.CURRENT_USERβ same energy asCURRENT_ROLE: alter the current user instead of an explicitly identified role.SESSION_USERβ alter the current session user instead of an explicitly identified role.SUPERUSERβ alters attributes originally set byCREATE ROLE. For more info, see theCREATE ROLEreference page.NOSUPERUSERβ alters attributes originally set byCREATE ROLE. For more info, see theCREATE ROLEreference page.CREATEDBβ alters attributes originally set byCREATE ROLE. For more info, see theCREATE ROLEreference page.NOCREATEDBβ alters attributes originally set byCREATE ROLE. For more info, see theCREATE ROLEreference page.CREATEROLEβ alters attributes originally set byCREATE ROLE. For more info, see theCREATE ROLEreference page.NOCREATEROLEβ alters attributes originally set byCREATE ROLE. For more info, see theCREATE ROLEreference page.INHERITβ alters attributes originally set byCREATE ROLE. For more info, see theCREATE ROLEreference page.NOINHERITβ alters attributes originally set byCREATE ROLE. For more info, see theCREATE ROLEreference page.LOGINβ alters attributes originally set byCREATE ROLE. For more info, see theCREATE ROLEreference page.NOLOGINβ alters attributes originally set byCREATE ROLE. For more info, see theCREATE ROLEreference page.REPLICATIONβ alters attributes originally set byCREATE ROLE. For more info, see theCREATE ROLEreference page.NOREPLICATIONβ alters attributes originally set byCREATE ROLE. For more info, see theCREATE ROLEreference page.BYPASSRLSβ alters attributes originally set byCREATE ROLE. For more info, see theCREATE ROLEreference page.NOBYPASSRLSβ alters attributes originally set byCREATE ROLE. For more info, see theCREATE ROLEreference page.CONNECTION LIMIT connlimitβ alters attributes originally set byCREATE ROLE. For more info, see theCREATE ROLEreference page.[ ENCRYPTED ] PASSWORD 'password'β alters attributes originally set byCREATE ROLE. For more info, see theCREATE ROLEreference page.PASSWORD NULLβ alters attributes originally set byCREATE ROLE. For more info, see theCREATE ROLEreference page.VALID UNTIL 'timestamp'β alters attributes originally set byCREATE ROLE. For more info, see theCREATE ROLEreference page.new_nameβ the new name of the role.database_nameβ the name of the database the configuration variable should be set in.configuration_parameter,valueβ set this role's session default for the specified configuration parameter to the given value. IfvalueisDEFAULTor, equivalently,RESETis used, the role-specific variable setting is removed, so the role will inherit the system-wide default setting in new sessions. UseRESET ALLto clear all role-specific settings.SET FROM CURRENTsaves the session's current value of the parameter as the role-specific value. IfIN DATABASEis specified, the configuration parameter is set or removed for the given role and database only.
Role-specific variable settings take effect only at login; SET ROLE and SET SESSION AUTHORIZATION do not process role-specific variable settings.
See SET(7) and Chapter 20 for more information about allowed parameter names and values. β¨
π NOTES π
- Use
CREATE ROLEto add new roles, andDROP ROLEto remove a role. easy peasy. ALTER ROLEcannot change a role's memberships. UseGRANTandREVOKEto do that. iykyk.- Caution must be exercised when specifying an unencrypted password with this command. The password will be transmitted to the server in cleartext, and it might also be logged in the client's command history or the server log. π¨
psql(1)contains a command\passwordthat can be used to change a role's password without exposing the cleartext password. use it bestie, protect ur peace. - It is also possible to tie a session default to a specific database rather than to a role; see
ALTER DATABASE(ALTER_DATABASE(7)). If there is a conflict, database-role-specific settings override role-specific ones, which in turn override database-specific ones. hierarchy is real π
π₯ 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 maintenance_work_mem parameter:
ALTER ROLE worker_bee SET maintenance_work_mem = 100000;
Give a role a non-default, database-specific setting of the client_min_messages parameter:
ALTER ROLE fred IN DATABASE devel SET client_min_messages = DEBUG;
β COMPATIBILITY β
The ALTER ROLE statement is a PostgreSQL extension. it's giving original, not a copy π
π«Ά SEE ALSO π«Ά
CREATE ROLE (CREATE_ROLE(7)), DROP ROLE (DROP_ROLE(7)), ALTER DATABASE (ALTER_DATABASE(7)), SET(7)
that's the whole page bestie, go forth and alter those roles with confidence πβ¨
PostgreSQL 14.24 Β· 2026 Β· ALTER ROLE(7) β mwah π
π¦ 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