Make LC_COLLATE and LC_CTYPE database-level settings. Collation and
[PostgreSQL.git] / doc / src / sgml / ref / alter_role.sgml
blob3d8f6cb4f3a5ae43bc5325347d5cd5c635f39c9b
1 <!--
2 $PostgreSQL$
3 PostgreSQL documentation
4 -->
6 <refentry id="SQL-ALTERROLE">
7 <refmeta>
8 <refentrytitle id="sql-alterrole-title">ALTER ROLE</refentrytitle>
9 <refmiscinfo>SQL - Language Statements</refmiscinfo>
10 </refmeta>
12 <refnamediv>
13 <refname>ALTER ROLE</refname>
14 <refpurpose>change a database role</refpurpose>
15 </refnamediv>
17 <indexterm zone="sql-alterrole">
18 <primary>ALTER ROLE</primary>
19 </indexterm>
21 <refsynopsisdiv>
22 <synopsis>
23 ALTER ROLE <replaceable class="PARAMETER">name</replaceable> [ [ WITH ] <replaceable class="PARAMETER">option</replaceable> [ ... ] ]
25 where <replaceable class="PARAMETER">option</replaceable> can be:
27 SUPERUSER | NOSUPERUSER
28 | CREATEDB | NOCREATEDB
29 | CREATEROLE | NOCREATEROLE
30 | CREATEUSER | NOCREATEUSER
31 | INHERIT | NOINHERIT
32 | LOGIN | NOLOGIN
33 | CONNECTION LIMIT <replaceable class="PARAMETER">connlimit</replaceable>
34 | [ ENCRYPTED | UNENCRYPTED ] PASSWORD '<replaceable class="PARAMETER">password</replaceable>'
35 | VALID UNTIL '<replaceable class="PARAMETER">timestamp</replaceable>'
37 ALTER ROLE <replaceable class="PARAMETER">name</replaceable> RENAME TO <replaceable>newname</replaceable>
39 ALTER ROLE <replaceable class="PARAMETER">name</replaceable> SET <replaceable>configuration_parameter</replaceable> { TO | = } { <replaceable>value</replaceable> | DEFAULT }
40 ALTER ROLE <replaceable class="PARAMETER">name</replaceable> SET <replaceable>configuration_parameter</replaceable> FROM CURRENT
41 ALTER ROLE <replaceable class="PARAMETER">name</replaceable> RESET <replaceable>configuration_parameter</replaceable>
42 ALTER ROLE <replaceable class="PARAMETER">name</replaceable> RESET ALL
43 </synopsis>
44 </refsynopsisdiv>
46 <refsect1>
47 <title>Description</title>
49 <para>
50 <command>ALTER ROLE</command> changes the attributes of a
51 <productname>PostgreSQL</productname> role.
52 </para>
54 <para>
55 The first variant of this command listed in the synopsis can change
56 many of the role attributes that can be specified in
57 <xref linkend="sql-createrole" endterm="sql-createrole-title">.
58 (All the possible attributes are covered,
59 except that there are no options for adding or removing memberships; use
60 <xref linkend="SQL-GRANT" endterm="SQL-GRANT-title"> and
61 <xref linkend="SQL-REVOKE" endterm="SQL-REVOKE-title"> for that.)
62 Attributes not mentioned in the command retain their previous settings.
63 Database superusers can change any of these settings for any role.
64 Roles having <literal>CREATEROLE</> privilege can change any of these
65 settings, but only for non-superuser roles.
66 Ordinary roles can only change their own password.
67 </para>
69 <para>
70 The second variant changes the name of the role.
71 Database superusers can rename any role.
72 Roles having <literal>CREATEROLE</> privilege can rename non-superuser
73 roles.
74 The current session user cannot be renamed.
75 (Connect as a different user if you need to do that.)
76 Because <literal>MD5</>-encrypted passwords use the role name as
77 cryptographic salt, renaming a role clears its password if the
78 password is <literal>MD5</>-encrypted.
79 </para>
81 <para>
82 The remaining variants change a role's session default for
83 a specified configuration variable. Whenever the role subsequently
84 starts a new session, the specified value becomes the session default,
85 overriding whatever setting is present in <filename>postgresql.conf</>
86 or has been received from the <command>postgres</command> command line.
87 (For a role without <literal>LOGIN</> privilege, session defaults have
88 no effect.)
89 Ordinary roles can change their own session defaults.
90 Superusers can change anyone's session defaults.
91 Roles having <literal>CREATEROLE</> privilege can change defaults for
92 non-superuser roles.
93 Certain variables cannot be set this way, or can only be
94 set if a superuser issues the command.
95 </para>
96 </refsect1>
98 <refsect1>
99 <title>Parameters</title>
101 <variablelist>
102 <varlistentry>
103 <term><replaceable class="PARAMETER">name</replaceable></term>
104 <listitem>
105 <para>
106 The name of the role whose attributes are to be altered.
107 </para>
108 </listitem>
109 </varlistentry>
111 <varlistentry>
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>
129 <listitem>
130 <para>
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.
135 </para>
136 </listitem>
137 </varlistentry>
139 <varlistentry>
140 <term><replaceable>newname</replaceable></term>
141 <listitem>
142 <para>
143 The new name of the role.
144 </para>
145 </listitem>
146 </varlistentry>
148 <varlistentry>
149 <term><replaceable>configuration_parameter</replaceable></term>
150 <term><replaceable>value</replaceable></term>
151 <listitem>
152 <para>
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.
162 </para>
164 <para>
165 See <xref linkend="sql-set" endterm="sql-set-title"> and <xref
166 linkend="runtime-config"> for more information about allowed
167 parameter names and values.
168 </para>
169 </listitem>
170 </varlistentry>
171 </variablelist>
172 </refsect1>
174 <refsect1>
175 <title>Notes</title>
177 <para>
178 Use <xref linkend="SQL-CREATEROLE" endterm="SQL-CREATEROLE-title">
179 to add new roles, and <xref linkend="SQL-DROPROLE"
180 endterm="SQL-DROPROLE-title"> to remove a role.
181 </para>
183 <para>
184 <command>ALTER ROLE</command> cannot change a role's memberships.
185 Use <xref linkend="SQL-GRANT" endterm="SQL-GRANT-title"> and
186 <xref linkend="SQL-REVOKE" endterm="SQL-REVOKE-title">
187 to do that.
188 </para>
190 <para>
191 Caution must be exercised when specifying an unencrypted password
192 with this command. The password will be transmitted to the server
193 in cleartext, and it might also be logged in the client's command
194 history or the server log. <xref linkend="app-psql"
195 endterm="app-psql-title"> contains a command
196 <command>\password</command> that can be used to safely change a
197 role's password.
198 </para>
200 <para>
201 It is also possible to tie a
202 session default to a specific database rather than to a role; see
203 <xref linkend="sql-alterdatabase" endterm="sql-alterdatabase-title">.
204 Role-specific settings override database-specific
205 ones if there is a conflict.
206 </para>
207 </refsect1>
209 <refsect1>
210 <title>Examples</title>
212 <para>
213 Change a role's password:
215 <programlisting>
216 ALTER ROLE davide WITH PASSWORD 'hu8jmn3';
217 </programlisting>
218 </para>
220 <para>
221 Remove a role's password:
223 <programlisting>
224 ALTER ROLE davide WITH PASSWORD NULL;
225 </programlisting>
226 </para>
228 <para>
229 Change a password expiration date, specifying that the password
230 should expire at midday on 4th May 2015 using
231 the time zone which is one hour ahead of <acronym>UTC</>:
232 <programlisting>
233 ALTER ROLE chris VALID UNTIL 'May 4 12:00:00 2015 +1';
234 </programlisting>
235 </para>
237 <para>
238 Make a password valid forever:
239 <programlisting>
240 ALTER ROLE fred VALID UNTIL 'infinity';
241 </programlisting>
242 </para>
244 <para>
245 Give a role the ability to create other roles and new databases:
247 <programlisting>
248 ALTER ROLE miriam CREATEROLE CREATEDB;
249 </programlisting>
250 </para>
252 <para>
253 Give a role a non-default setting of the
254 <xref linkend="guc-maintenance-work-mem"> parameter:
256 <programlisting>
257 ALTER ROLE worker_bee SET maintenance_work_mem = 100000;
258 </programlisting>
259 </para>
260 </refsect1>
262 <refsect1>
263 <title>Compatibility</title>
265 <para>
266 The <command>ALTER ROLE</command> statement is a
267 <productname>PostgreSQL</productname> extension.
268 </para>
269 </refsect1>
271 <refsect1>
272 <title>See Also</title>
274 <simplelist type="inline">
275 <member><xref linkend="sql-createrole" endterm="sql-createrole-title"></member>
276 <member><xref linkend="sql-droprole" endterm="sql-droprole-title"></member>
277 <member><xref linkend="sql-set" endterm="sql-set-title"></member>
278 </simplelist>
279 </refsect1>
280 </refentry>