ALTER ROLE
The ALTER ROLE statement changes an existing role: its attributes (LOGIN, CREATEDB, …), its password, or its name. ALTER USER is an alias.
Examples
Start with a login role:
Query
CREATE ROLE doc_worker LOGIN PASSWORD 'worker_secret';Add an attribute:
Query
ALTER ROLE doc_worker CREATEDB;Several attributes can be changed in one statement; the NO-prefixed form removes an attribute:
Query
ALTER ROLE doc_worker NOCREATEDB NOLOGIN;Rotate the password:
Query
ALTER ROLE doc_worker PASSWORD 'rotated_secret';Set a password expiry — after this timestamp, password authentication fails:
Query
ALTER ROLE doc_worker VALID UNTIL '2099-12-31 00:00:00+00';Rename the role:
Query
ALTER ROLE doc_worker RENAME TO doc_worker_renamed;Contradictory attributes are rejected:
Query
ALTER ROLE doc_worker_renamed SUPERUSER NOSUPERUSER;Result
error db error: ERROR: conflicting or redundant optionsAltering a role that does not exist is an error:
Query
ALTER ROLE doc_missing LOGIN;Result
error db error: ERROR: role "doc_missing" does not existNotes
- Changing role attributes requires the
CREATEROLEattribute (or superuser); only a superuser can grant or removeSUPERUSER. PASSWORD NULLremoves the stored password, disabling password authentication for the role.CONNECTION LIMITis accepted and stored but is not currently enforced at connect time.
See also
- CREATE ROLE — create a role
- DROP ROLE — remove roles
- GRANT — grant privileges or role membership