4 ALTER ROLE — change a database role
8 ALTER ROLE role_specification [ WITH ] option [ ... ]
12 SUPERUSER | NOSUPERUSER
13 | CREATEDB | NOCREATEDB
14 | CREATEROLE | NOCREATEROLE
17 | REPLICATION | NOREPLICATION
18 | BYPASSRLS | NOBYPASSRLS
19 | CONNECTION LIMIT connlimit
20 | [ ENCRYPTED ] PASSWORD 'password' | PASSWORD NULL
21 | VALID UNTIL 'timestamp'
23 ALTER ROLE name RENAME TO new_name
25 ALTER ROLE { role_specification | ALL } [ IN DATABASE database_name ] SET config
26 uration_parameter { TO | = } { value | DEFAULT }
27 ALTER ROLE { role_specification | ALL } [ IN DATABASE database_name ] SET config
28 uration_parameter FROM CURRENT
29 ALTER ROLE { role_specification | ALL } [ IN DATABASE database_name ] RESET conf
31 ALTER ROLE { role_specification | ALL } [ IN DATABASE database_name ] RESET ALL
33 where role_specification can be:
42 ALTER ROLE changes the attributes of a PostgreSQL role.
44 The first variant of this command listed in the synopsis can change
45 many of the role attributes that can be specified in CREATE ROLE. (All
46 the possible attributes are covered, except that there are no options
47 for adding or removing memberships; use GRANT and REVOKE for that.)
48 Attributes not mentioned in the command retain their previous settings.
49 Database superusers can change any of these settings for any role,
50 except for changing the SUPERUSER property for the bootstrap superuser.
51 Non-superuser roles having CREATEROLE privilege can change most of
52 these properties, but only for non-superuser and non-replication roles
53 for which they have been granted ADMIN OPTION. Non-superusers cannot
54 change the SUPERUSER property and can change the CREATEDB, REPLICATION,
55 and BYPASSRLS properties only if they possess the corresponding
56 property themselves. Ordinary roles can only change their own password.
58 The second variant changes the name of the role. Database superusers
59 can rename any role. Roles having CREATEROLE privilege can rename
60 non-superuser roles for which they have been granted ADMIN OPTION. The
61 current session user cannot be renamed. (Connect as a different user if
62 you need to do that.) Because MD5-encrypted passwords use the role name
63 as cryptographic salt, renaming a role clears its password if the
64 password is MD5-encrypted.
66 The remaining variants change a role's session default for a
67 configuration variable, either for all databases or, when the IN
68 DATABASE clause is specified, only for sessions in the named database.
69 If ALL is specified instead of a role name, this changes the setting
70 for all roles. Using ALL with IN DATABASE is effectively the same as
71 using the command ALTER DATABASE ... SET ....
73 Whenever the role subsequently starts a new session, the specified
74 value becomes the session default, overriding whatever setting is
75 present in postgresql.conf or has been received from the postgres
76 command line. This only happens at login time; executing SET ROLE or
77 SET SESSION AUTHORIZATION does not cause new configuration values to be
78 set. Settings set for all databases are overridden by database-specific
79 settings attached to a role. Settings for specific databases or
80 specific roles override settings for all roles.
82 Superusers can change anyone's session defaults. Roles having
83 CREATEROLE privilege can change defaults for non-superuser roles for
84 which they have been granted ADMIN OPTION. Ordinary roles can only set
85 defaults for themselves. Certain configuration variables cannot be set
86 this way, or can only be set if a superuser issues the command. Only
87 superusers can change a setting for all roles in all databases.
92 The name of the role whose attributes are to be altered.
96 Alter the current user instead of an explicitly identified role.
99 Alter the current session user instead of an explicitly
116 CONNECTION LIMIT connlimit
117 [ ENCRYPTED ] PASSWORD 'password'
119 VALID UNTIL 'timestamp' #
120 These clauses alter attributes originally set by CREATE ROLE.
121 For more information, see the CREATE ROLE reference page.
124 The new name of the role.
127 The name of the database the configuration variable should be
130 configuration_parameter
132 Set this role's session default for the specified configuration
133 parameter to the given value. If value is DEFAULT or,
134 equivalently, RESET is used, the role-specific variable setting
135 is removed, so the role will inherit the system-wide default
136 setting in new sessions. Use RESET ALL to clear all
137 role-specific settings. SET FROM CURRENT saves the session's
138 current value of the parameter as the role-specific value. If IN
139 DATABASE is specified, the configuration parameter is set or
140 removed for the given role and database only.
142 Role-specific variable settings take effect only at login; SET
143 ROLE and SET SESSION AUTHORIZATION do not process role-specific
146 See SET and Chapter 19 for more information about allowed
147 parameter names and values.
151 Use CREATE ROLE to add new roles, and DROP ROLE to remove a role.
153 ALTER ROLE cannot change a role's memberships. Use GRANT and REVOKE to
156 Caution must be exercised when specifying an unencrypted password with
157 this command. The password will be transmitted to the server in
158 cleartext, and it might also be logged in the client's command history
159 or the server log. psql contains a command \password that can be used
160 to change a role's password without exposing the cleartext password.
162 It is also possible to tie a session default to a specific database
163 rather than to a role; see ALTER DATABASE. If there is a conflict,
164 database-role-specific settings override role-specific ones, which in
165 turn override database-specific ones.
169 Change a role's password:
170 ALTER ROLE davide WITH PASSWORD 'hu8jmn3';
172 Remove a role's password:
173 ALTER ROLE davide WITH PASSWORD NULL;
175 Change a password expiration date, specifying that the password should
176 expire at midday on 4th May 2015 using the time zone which is one hour
178 ALTER ROLE chris VALID UNTIL 'May 4 12:00:00 2015 +1';
180 Make a password valid forever:
181 ALTER ROLE fred VALID UNTIL 'infinity';
183 Give a role the ability to manage other roles and create new databases:
184 ALTER ROLE miriam CREATEROLE CREATEDB;
186 Give a role a non-default setting of the maintenance_work_mem
188 ALTER ROLE worker_bee SET maintenance_work_mem = 100000;
190 Give a role a non-default, database-specific setting of the
191 client_min_messages parameter:
192 ALTER ROLE fred IN DATABASE devel SET client_min_messages = DEBUG;
196 The ALTER ROLE statement is a PostgreSQL extension.
200 CREATE ROLE, DROP ROLE, ALTER DATABASE, SET