ALTER_ROLE(7pg14)

πŸ“¦ version 14.24, in opensuse-leap 16.0

✨ 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 CREATEROLE privilege can change any of these settings except SUPERUSER, REPLICATION, and BYPASSRLS β€” 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 as CURRENT_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 by CREATE ROLE. For more info, see the CREATE ROLE reference page.
  • NOSUPERUSER β€” alters attributes originally set by CREATE ROLE. For more info, see the CREATE ROLE reference page.
  • CREATEDB β€” alters attributes originally set by CREATE ROLE. For more info, see the CREATE ROLE reference page.
  • NOCREATEDB β€” alters attributes originally set by CREATE ROLE. For more info, see the CREATE ROLE reference page.
  • CREATEROLE β€” alters attributes originally set by CREATE ROLE. For more info, see the CREATE ROLE reference page.
  • NOCREATEROLE β€” alters attributes originally set by CREATE ROLE. For more info, see the CREATE ROLE reference page.
  • INHERIT β€” alters attributes originally set by CREATE ROLE. For more info, see the CREATE ROLE reference page.
  • NOINHERIT β€” alters attributes originally set by CREATE ROLE. For more info, see the CREATE ROLE reference page.
  • LOGIN β€” alters attributes originally set by CREATE ROLE. For more info, see the CREATE ROLE reference page.
  • NOLOGIN β€” alters attributes originally set by CREATE ROLE. For more info, see the CREATE ROLE reference page.
  • REPLICATION β€” alters attributes originally set by CREATE ROLE. For more info, see the CREATE ROLE reference page.
  • NOREPLICATION β€” alters attributes originally set by CREATE ROLE. For more info, see the CREATE ROLE reference page.
  • BYPASSRLS β€” alters attributes originally set by CREATE ROLE. For more info, see the CREATE ROLE reference page.
  • NOBYPASSRLS β€” alters attributes originally set by CREATE ROLE. For more info, see the CREATE ROLE reference page.
  • CONNECTION LIMIT connlimit β€” alters attributes originally set by CREATE ROLE. For more info, see the CREATE ROLE reference page.
  • [ ENCRYPTED ] PASSWORD 'password' β€” alters attributes originally set by CREATE ROLE. For more info, see the CREATE ROLE reference page.
  • PASSWORD NULL β€” alters attributes originally set by CREATE ROLE. For more info, see the CREATE ROLE reference page.
  • VALID UNTIL 'timestamp' β€” alters attributes originally set by CREATE ROLE. For more info, see the CREATE ROLE reference 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. If value is DEFAULT or, equivalently, RESET is used, the role-specific variable setting is removed, so the role will inherit the system-wide default setting in new sessions. Use RESET ALL to clear all role-specific settings. SET FROM CURRENT saves the session's current value of the parameter as the role-specific value. If IN DATABASE is 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 ROLE to add new roles, and DROP ROLE to remove a role. easy peasy.
  • ALTER ROLE cannot change a role's memberships. Use GRANT and REVOKE to 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 \password that 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