3
PostgreSQL documentation
6
<refentry id="SQL-ALTERROLE">
8
<refentrytitle id="sql-alterrole-title">ALTER ROLE</refentrytitle>
9
<manvolnum>7</manvolnum>
10
<refmiscinfo>SQL - Language Statements</refmiscinfo>
14
<refname>ALTER ROLE</refname>
15
<refpurpose>change a database role</refpurpose>
18
<indexterm zone="sql-alterrole">
19
<primary>ALTER ROLE</primary>
24
ALTER ROLE <replaceable class="PARAMETER">name</replaceable> [ [ WITH ] <replaceable class="PARAMETER">option</replaceable> [ ... ] ]
26
where <replaceable class="PARAMETER">option</replaceable> can be:
28
SUPERUSER | NOSUPERUSER
29
| CREATEDB | NOCREATEDB
30
| CREATEROLE | NOCREATEROLE
31
| CREATEUSER | NOCREATEUSER
34
| CONNECTION LIMIT <replaceable class="PARAMETER">connlimit</replaceable>
35
| [ ENCRYPTED | UNENCRYPTED ] PASSWORD '<replaceable class="PARAMETER">password</replaceable>'
36
| VALID UNTIL '<replaceable class="PARAMETER">timestamp</replaceable>'
38
ALTER ROLE <replaceable class="PARAMETER">name</replaceable> RENAME TO <replaceable>newname</replaceable>
40
ALTER ROLE <replaceable class="PARAMETER">name</replaceable> SET <replaceable>configuration_parameter</replaceable> { TO | = } { <replaceable>value</replaceable> | DEFAULT }
41
ALTER ROLE <replaceable class="PARAMETER">name</replaceable> SET <replaceable>configuration_parameter</replaceable> FROM CURRENT
42
ALTER ROLE <replaceable class="PARAMETER">name</replaceable> RESET <replaceable>configuration_parameter</replaceable>
43
ALTER ROLE <replaceable class="PARAMETER">name</replaceable> RESET ALL
48
<title>Description</title>
51
<command>ALTER ROLE</command> changes the attributes of a
52
<productname>PostgreSQL</productname> role.
56
The first variant of this command listed in the synopsis can change
57
many of the role attributes that can be specified in
58
<xref linkend="sql-createrole" endterm="sql-createrole-title">.
59
(All the possible attributes are covered,
60
except that there are no options for adding or removing memberships; use
61
<xref linkend="SQL-GRANT" endterm="SQL-GRANT-title"> and
62
<xref linkend="SQL-REVOKE" endterm="SQL-REVOKE-title"> for that.)
63
Attributes not mentioned in the command retain their previous settings.
64
Database superusers can change any of these settings for any role.
65
Roles having <literal>CREATEROLE</> privilege can change any of these
66
settings, but only for non-superuser roles.
67
Ordinary roles can only change their own password.
71
The second variant changes the name of the role.
72
Database superusers can rename any role.
73
Roles having <literal>CREATEROLE</> privilege can rename non-superuser
75
The current session user cannot be renamed.
76
(Connect as a different user if you need to do that.)
77
Because <literal>MD5</>-encrypted passwords use the role name as
78
cryptographic salt, renaming a role clears its password if the
79
password is <literal>MD5</>-encrypted.
83
The remaining variants change a role's session default for a
84
specified configuration variable. Whenever the role subsequently
85
starts a new session, the specified value becomes the session
86
default, overriding whatever setting is present in
87
<filename>postgresql.conf</> or has been received from the postgres
88
command line. This only happens at login time, so configuration
89
settings associated with a role to which you've <xref
90
linkend="sql-set-role" endterm="sql-set-role-title"> will be ignored.
91
Superusers can change anyone's session defaults. Roles having
92
<literal>CREATEROLE</> privilege can change defaults for non-superuser
93
roles. Certain variables cannot be set this way, or can only be
94
set if a superuser issues the command.
99
<title>Parameters</title>
103
<term><replaceable class="PARAMETER">name</replaceable></term>
106
The name of the role whose attributes are to be altered.
112
<term><literal>SUPERUSER</literal></term>
113
<term><literal>NOSUPERUSER</literal></term>
114
<term><literal>CREATEDB</></term>
115
<term><literal>NOCREATEDB</></term>
116
<term><literal>CREATEROLE</literal></term>
117
<term><literal>NOCREATEROLE</literal></term>
118
<term><literal>CREATEUSER</literal></term>
119
<term><literal>NOCREATEUSER</literal></term>
120
<term><literal>INHERIT</literal></term>
121
<term><literal>NOINHERIT</literal></term>
122
<term><literal>LOGIN</literal></term>
123
<term><literal>NOLOGIN</literal></term>
124
<term><literal>CONNECTION LIMIT</literal> <replaceable class="parameter">connlimit</replaceable></term>
125
<term><literal>PASSWORD</> <replaceable class="parameter">password</replaceable></term>
126
<term><literal>ENCRYPTED</></term>
127
<term><literal>UNENCRYPTED</></term>
128
<term><literal>VALID UNTIL</literal> '<replaceable class="parameter">timestamp</replaceable>'</term>
131
These clauses alter attributes originally set by
132
<xref linkend="SQL-CREATEROLE"
133
endterm="SQL-CREATEROLE-title">. For more information, see the
134
<command>CREATE ROLE</command> reference page.
140
<term><replaceable>newname</replaceable></term>
143
The new name of the role.
149
<term><replaceable>configuration_parameter</replaceable></term>
150
<term><replaceable>value</replaceable></term>
153
Set this role's session default for the specified configuration
154
parameter to the given value. If
155
<replaceable>value</replaceable> is <literal>DEFAULT</literal>
156
or, equivalently, <literal>RESET</literal> is used, the
157
role-specific variable setting is removed, so the role will
158
inherit the system-wide default setting in new sessions. Use
159
<literal>RESET ALL</literal> to clear all role-specific settings.
160
<literal>SET FROM CURRENT</> saves the session's current value of
161
the parameter as the role-specific value.
165
Role-specific variable setting take effect only at login;
166
<xref linkend="sql-set-role" endterm="sql-set-role-title">
167
does not process role-specific variable settings.
171
See <xref linkend="sql-set" endterm="sql-set-title"> and <xref
172
linkend="runtime-config"> for more information about allowed
173
parameter names and values.
184
Use <xref linkend="SQL-CREATEROLE" endterm="SQL-CREATEROLE-title">
185
to add new roles, and <xref linkend="SQL-DROPROLE"
186
endterm="SQL-DROPROLE-title"> to remove a role.
190
<command>ALTER ROLE</command> cannot change a role's memberships.
191
Use <xref linkend="SQL-GRANT" endterm="SQL-GRANT-title"> and
192
<xref linkend="SQL-REVOKE" endterm="SQL-REVOKE-title">
197
Caution must be exercised when specifying an unencrypted password
198
with this command. The password will be transmitted to the server
199
in cleartext, and it might also be logged in the client's command
200
history or the server log. <xref linkend="app-psql"
201
endterm="app-psql-title"> contains a command
202
<command>\password</command> that can be used to safely change a
207
It is also possible to tie a
208
session default to a specific database rather than to a role; see
209
<xref linkend="sql-alterdatabase" endterm="sql-alterdatabase-title">.
210
Role-specific settings override database-specific
211
ones if there is a conflict.
216
<title>Examples</title>
219
Change a role's password:
222
ALTER ROLE davide WITH PASSWORD 'hu8jmn3';
227
Remove a role's password:
230
ALTER ROLE davide WITH PASSWORD NULL;
235
Change a password expiration date, specifying that the password
236
should expire at midday on 4th May 2015 using
237
the time zone which is one hour ahead of <acronym>UTC</>:
239
ALTER ROLE chris VALID UNTIL 'May 4 12:00:00 2015 +1';
244
Make a password valid forever:
246
ALTER ROLE fred VALID UNTIL 'infinity';
251
Give a role the ability to create other roles and new databases:
254
ALTER ROLE miriam CREATEROLE CREATEDB;
259
Give a role a non-default setting of the
260
<xref linkend="guc-maintenance-work-mem"> parameter:
263
ALTER ROLE worker_bee SET maintenance_work_mem = 100000;
269
<title>Compatibility</title>
272
The <command>ALTER ROLE</command> statement is a
273
<productname>PostgreSQL</productname> extension.
278
<title>See Also</title>
280
<simplelist type="inline">
281
<member><xref linkend="sql-createrole" endterm="sql-createrole-title"></member>
282
<member><xref linkend="sql-droprole" endterm="sql-droprole-title"></member>
283
<member><xref linkend="sql-set" endterm="sql-set-title"></member>