3 .\" Author: The PostgreSQL Global Development Group
4 .\" Generator: DocBook XSL Stylesheets vsnapshot <http://docbook.sf.net/>
6 .\" Manual: PostgreSQL 18.0 Documentation
7 .\" Source: PostgreSQL 18.0
10 .TH "ALTER ROLE" "7" "2025" "PostgreSQL 18.0" "PostgreSQL 18.0 Documentation"
11 .\" -----------------------------------------------------------------
12 .\" * Define some portability stuff
13 .\" -----------------------------------------------------------------
14 .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
15 .\" http://bugs.debian.org/507673
16 .\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html
17 .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
20 .\" -----------------------------------------------------------------
21 .\" * set default formatting
22 .\" -----------------------------------------------------------------
23 .\" disable hyphenation
25 .\" disable justification (adjust text to left margin only)
27 .\" -----------------------------------------------------------------
28 .\" * MAIN CONTENT STARTS HERE *
29 .\" -----------------------------------------------------------------
31 ALTER_ROLE \- change a database role
35 ALTER ROLE \fIrole_specification\fR [ WITH ] \fIoption\fR [ \&.\&.\&. ]
37 where \fIoption\fR can be:
39 SUPERUSER | NOSUPERUSER
40 | CREATEDB | NOCREATEDB
41 | CREATEROLE | NOCREATEROLE
44 | REPLICATION | NOREPLICATION
45 | BYPASSRLS | NOBYPASSRLS
46 | CONNECTION LIMIT \fIconnlimit\fR
47 | [ ENCRYPTED ] PASSWORD \*(Aq\fIpassword\fR\*(Aq | PASSWORD NULL
48 | VALID UNTIL \*(Aq\fItimestamp\fR\*(Aq
50 ALTER ROLE \fIname\fR RENAME TO \fInew_name\fR
52 ALTER ROLE { \fIrole_specification\fR | ALL } [ IN DATABASE \fIdatabase_name\fR ] SET \fIconfiguration_parameter\fR { TO | = } { \fIvalue\fR | DEFAULT }
53 ALTER ROLE { \fIrole_specification\fR | ALL } [ IN DATABASE \fIdatabase_name\fR ] SET \fIconfiguration_parameter\fR FROM CURRENT
54 ALTER ROLE { \fIrole_specification\fR | ALL } [ IN DATABASE \fIdatabase_name\fR ] RESET \fIconfiguration_parameter\fR
55 ALTER ROLE { \fIrole_specification\fR | ALL } [ IN DATABASE \fIdatabase_name\fR ] RESET ALL
57 where \fIrole_specification\fR can be:
67 changes the attributes of a
71 The first variant of this command listed in the synopsis can change many of the role attributes that can be specified in
72 \fBCREATE ROLE\fR\&. (All the possible attributes are covered, except that there are no options for adding or removing memberships; use
76 for that\&.) Attributes not mentioned in the command retain their previous settings\&. Database superusers can change any of these settings for any role, except for changing the
79 bootstrap superuser\&. Non\-superuser roles having
81 privilege can change most of these properties, but only for non\-superuser and non\-replication roles for which they have been granted
82 ADMIN OPTION\&. Non\-superusers cannot change the
84 property and can change the
88 properties only if they possess the corresponding property themselves\&. Ordinary roles can only change their own password\&.
90 The second variant changes the name of the role\&. Database superusers can rename any role\&. Roles having
92 privilege can rename non\-superuser roles for which they have been granted
93 ADMIN OPTION\&. The current session user cannot be renamed\&. (Connect as a different user if you need to do that\&.) Because
94 MD5\-encrypted passwords use the role name as cryptographic salt, renaming a role clears its password if the password is
97 The remaining variants change a role\*(Aqs session default for a configuration variable, either for all databases or, when the
99 clause is specified, only for sessions in the named database\&. If
101 is specified instead of a role name, this changes the setting for all roles\&. Using
105 is effectively the same as using the command
106 ALTER DATABASE \&.\&.\&. SET \&.\&.\&.\&.
108 Whenever the role subsequently starts a new session, the specified value becomes the session default, overriding whatever setting is present in
110 or has been received from the
112 command line\&. This only happens at login time; executing
115 \fBSET SESSION AUTHORIZATION\fR
116 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\&.
118 Superusers can change anyone\*(Aqs session defaults\&. Roles having
120 privilege can change defaults for non\-superuser roles for which they have been granted
121 ADMIN OPTION\&. 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\&.
126 The name of the role whose attributes are to be altered\&.
133 Alter the current user instead of an explicitly identified role\&.
138 Alter the current session user instead of an explicitly identified role\&.
169 CONNECTION LIMIT \fIconnlimit\fR
171 [ ENCRYPTED ] PASSWORD \*(Aq\fIpassword\fR\*(Aq
175 VALID UNTIL \*(Aq\fItimestamp\fR\*(Aq
177 These clauses alter attributes originally set by
178 \fBCREATE ROLE\fR\&. For more information, see the
185 The new name of the role\&.
190 The name of the database the configuration variable should be set in\&.
193 \fIconfiguration_parameter\fR
197 Set this role\*(Aqs session default for the specified configuration parameter to the given value\&. If
203 is used, the role\-specific variable setting is removed, so the role will inherit the system\-wide default setting in new sessions\&. Use
205 to clear all role\-specific settings\&.
207 saves the session\*(Aqs current value of the parameter as the role\-specific value\&. If
209 is specified, the configuration parameter is set or removed for the given role and database only\&.
211 Role\-specific variable settings take effect only at login;
214 \fBSET SESSION AUTHORIZATION\fR
215 do not process role\-specific variable settings\&.
221 for more information about allowed parameter names and values\&.
227 to add new roles, and
232 cannot change a role\*(Aqs memberships\&. Use
238 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\*(Aqs command history or the server log\&.
242 that can be used to change a role\*(Aqs password without exposing the cleartext password\&.
244 It is also possible to tie a session default to a specific database rather than to a role; see
245 ALTER DATABASE (\fBALTER_DATABASE\fR(7))\&. If there is a conflict, database\-role\-specific settings override role\-specific ones, which in turn override database\-specific ones\&.
248 Change a role\*(Aqs password:
254 ALTER ROLE davide WITH PASSWORD \*(Aqhu8jmn3\*(Aq;
260 Remove a role\*(Aqs password:
266 ALTER ROLE davide WITH PASSWORD NULL;
272 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
279 ALTER ROLE chris VALID UNTIL \*(AqMay 4 12:00:00 2015 +1\*(Aq;
285 Make a password valid forever:
291 ALTER ROLE fred VALID UNTIL \*(Aqinfinity\*(Aq;
297 Give a role the ability to manage other roles and create new databases:
303 ALTER ROLE miriam CREATEROLE CREATEDB;
309 Give a role a non\-default setting of the
317 ALTER ROLE worker_bee SET maintenance_work_mem = 100000;
323 Give a role a non\-default, database\-specific setting of the
331 ALTER ROLE fred IN DATABASE devel SET client_min_messages = DEBUG;
344 CREATE ROLE (\fBCREATE_ROLE\fR(7)), DROP ROLE (\fBDROP_ROLE\fR(7)), ALTER DATABASE (\fBALTER_DATABASE\fR(7)), \fBSET\fR(7)