postgresql_16:7.1.76.3 Notes
PostgreSQL 16 > Reference > SQL Commands > CREATE ROLE > Notes
Use ALTER ROLE (see postgresql_16:7.1.24) to change the attributes of a role, and DROP ROLE (see postgresql_16:7.1.124) to remove a role. All the attributes specified by CREATE ROLE can be modified by later ALTER ROLE commands.
The preferred way to add and remove members of roles that are being used as groups is to use GRANT (see postgresql_16:7.1.148) and REVOKE (see postgresql_16:7.1.164).
The VALID UNTIL clause defines an expiration time for a password only, not for the role per se. In particular, the expiration time is not enforced when logging in using a non-password-based authentication method.
The role attributes defined here are non-inheritable, i.e., being a member of a role with, e.g., CREATEDB will not allow the member to create new databases even if the membership grant has the INHERIT option. Of course, if the membership grant has the SET option the member role would be able to SET ROLE (see postgresql_16:7.1.174) to the createdb role and then create a new database.
The membership grants created by the IN ROLE, ROLE, and ADMIN clauses have the role executing this command as the grantor.
The INHERIT attribute is the default for reasons of backwards compatibility: in prior releases of PostgreSQL, users always had access to all privileges of groups they were members of. However, NOINHERIT provides a closer match to the semantics specified in the SQL standard.
PostgreSQL includes a program (see postgresql_16:7.2.3) that has the same functionality as CREATE ROLE (in fact, it calls this command) but can be run from the command shell.
The CONNECTION LIMIT option is only enforced approximately; if two new sessions start at about the same time when just one connection “slot” remains for the role, it is possible that both will fail. Also, the limit is never enforced for superusers.
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. The command (see postgresql_16:7.2.3), however, transmits the password encrypted. Also, (see postgresql_16:7.2.18) contains a command \password that can be used to safely change the password later.