1999-07-22 17:09:15 +02:00
<!--
2003-08-31 19:32:24 +02:00
$Header: /cvsroot/pgsql/doc/src/sgml/ref/alter_user.sgml,v 1.29 2003/08/31 17:32:21 petere Exp $
2001-12-08 04:24:40 +01:00
PostgreSQL documentation
1999-07-22 17:09:15 +02:00
-->
1999-07-06 19:16:42 +02:00
<refentry id="SQL-ALTERUSER">
<refmeta>
2002-02-27 22:14:54 +01:00
<refentrytitle id="sql-alteruser-title">ALTER USER</refentrytitle>
1999-07-06 19:16:42 +02:00
<refmiscinfo>SQL - Language Statements</refmiscinfo>
</refmeta>
2002-02-27 22:14:54 +01:00
1999-07-06 19:16:42 +02:00
<refnamediv>
2002-02-27 22:14:54 +01:00
<refname>ALTER USER</refname>
<refpurpose>change a database user account</refpurpose>
1998-12-29 03:24:47 +01:00
</refnamediv>
2002-02-27 22:14:54 +01:00
2003-08-31 19:32:24 +02:00
<indexterm zone="sql-alteruser">
<primary>ALTER USER</primary>
</indexterm>
1999-07-06 19:16:42 +02:00
<refsynopsisdiv>
2002-02-27 22:14:54 +01:00
<synopsis>
2001-07-11 00:09:29 +02:00
ALTER USER <replaceable class="PARAMETER">username</replaceable> [ [ WITH ] <replaceable class="PARAMETER">option</replaceable> [ ... ] ]
where <replaceable class="PARAMETER">option</replaceable> can be:
2003-04-15 15:25:08 +02:00
[ ENCRYPTED | UNENCRYPTED ] PASSWORD '<replaceable class="PARAMETER">password</replaceable>'
2002-02-27 22:14:54 +01:00
| CREATEDB | NOCREATEDB
| CREATEUSER | NOCREATEUSER
| VALID UNTIL '<replaceable class="PARAMETER">abstime</replaceable>'
2002-03-01 23:45:19 +01:00
2003-06-27 16:45:32 +02:00
ALTER USER <replaceable class="PARAMETER">username</replaceable> RENAME TO <replaceable>newname</replaceable>
2002-03-01 23:45:19 +01:00
ALTER USER <replaceable class="PARAMETER">username</replaceable> SET <replaceable>variable</replaceable> { TO | = } { <replaceable>value</replaceable> | DEFAULT }
ALTER USER <replaceable class="PARAMETER">username</replaceable> RESET <replaceable>variable</replaceable>
2002-02-27 22:14:54 +01:00
</synopsis>
</refsynopsisdiv>
<refsect1>
<title>Description</title>
1999-07-06 19:16:42 +02:00
2002-02-27 22:14:54 +01:00
<para>
<command>ALTER USER</command> is used to change the attributes of a
<productname>PostgreSQL</productname> user account. Attributes not
mentioned in the command retain their previous settings.
</para>
<para>
2002-03-01 23:45:19 +01:00
The first variant of this command in the synopsis changes certain
global user privileges and authentication settings. (See below for
2003-04-15 15:25:08 +02:00
details.) Only a database superuser can change these privileges and
the password expiration with this command. Ordinary users can only
2002-03-01 23:45:19 +01:00
change their own password.
</para>
<para>
2003-06-27 16:45:32 +02:00
The second variant changes the name of the user. Only a database
superuser can rename user accounts. The session user cannot be
renamed. (Connect as a different user if you need to do that.)
</para>
<para>
The third and the fourth variant change a user's session default for
2002-03-01 23:45:19 +01:00
a specified configuration variable. Whenever the user subsequently
2002-05-17 03:19:19 +02:00
starts a new session, the specified value becomes the session default,
overriding whatever setting is present in <filename>postgresql.conf</>
2003-04-15 15:25:08 +02:00
or has been received from the <command>postmaster</command> command line.
2002-05-17 03:19:19 +02:00
Ordinary users can change their own session defaults.
Superusers can change anyone's session defaults.
2002-02-27 22:14:54 +01:00
</para>
2003-04-15 15:25:08 +02:00
</refsect1>
2002-02-27 22:14:54 +01:00
2003-04-15 15:25:08 +02:00
<refsect1>
<title>Parameters</title>
1999-07-06 19:16:42 +02:00
<variablelist>
<varlistentry>
2000-01-14 23:11:38 +01:00
<term><replaceable class="PARAMETER">username</replaceable></term>
1999-07-06 19:16:42 +02:00
<listitem>
<para>
2002-02-27 22:14:54 +01:00
The name of the user whose attributes are to be altered.
1999-07-06 19:16:42 +02:00
</para>
</listitem>
</varlistentry>
<varlistentry>
2001-09-21 22:31:49 +02:00
<term><replaceable class="PARAMETER">password</replaceable></term>
1999-07-06 19:16:42 +02:00
<listitem>
<para>
The new password to be used for this account.
2001-09-21 22:31:49 +02:00
</para>
</listitem>
</varlistentry>
<varlistentry>
2002-02-27 22:14:54 +01:00
<term><literal>ENCRYPTED</literal></term>
<term><literal>UNENCRYPTED</literal></term>
2001-09-21 22:31:49 +02:00
<listitem>
2002-02-27 22:14:54 +01:00
<para>
These key words control whether the password is stored
encrypted in <literal>pg_shadow</>. (See
2001-09-21 22:31:49 +02:00
<xref linkend="SQL-CREATEUSER" endterm="SQL-CREATEUSER-title">
for more information about this choice.)
1999-07-06 19:16:42 +02:00
</para>
</listitem>
</varlistentry>
1999-11-30 04:57:29 +01:00
<varlistentry>
2002-02-27 22:14:54 +01:00
<term><literal>CREATEDB</literal></term>
<term><literal>NOCREATEDB</literal></term>
1999-11-30 04:57:29 +01:00
<listitem>
2002-02-27 22:14:54 +01:00
<para>
These clauses define a user's ability to create databases. If
2003-04-15 15:25:08 +02:00
<literal>CREATEDB</literal> is specified, the user
will be allowed to create his own databases. Using
2002-02-27 22:14:54 +01:00
<literal>NOCREATEDB</literal> will deny a user the ability to
create databases.
1999-11-30 04:57:29 +01:00
</para>
</listitem>
</varlistentry>
1999-07-06 19:16:42 +02:00
<varlistentry>
2002-02-27 22:14:54 +01:00
<term><literal>CREATEUSER</literal></term>
<term><literal>NOCREATEUSER</literal></term>
1999-07-06 19:16:42 +02:00
<listitem>
<para>
2000-01-14 23:11:38 +01:00
These clauses determine whether a user will be permitted to
create new users himself. This option will also make the user
2002-02-27 22:14:54 +01:00
a superuser who can override all access restrictions.
1999-07-06 19:16:42 +02:00
</para>
</listitem>
</varlistentry>
<varlistentry>
2000-01-14 23:11:38 +01:00
<term><replaceable class="PARAMETER">abstime</replaceable></term>
1999-07-06 19:16:42 +02:00
<listitem>
<para>
The date (and, optionally, the time)
2003-03-20 21:05:32 +01:00
at which this user's password is to expire. To set the password
2003-04-15 15:25:08 +02:00
never to expire, use <literal>'infinity'</>.
1999-07-06 19:16:42 +02:00
</para>
</listitem>
</varlistentry>
2002-03-01 23:45:19 +01:00
2003-06-27 16:45:32 +02:00
<varlistentry>
<term><replaceable>newname</replaceable></term>
<listitem>
<para>
The new name of the user.
</para>
</listitem>
</varlistentry>
2002-03-01 23:45:19 +01:00
<varlistentry>
<term><replaceable>variable</replaceable></term>
<term><replaceable>value</replaceable></term>
<listitem>
<para>
2002-05-17 03:19:19 +02:00
Set this user's session default for the specified configuration
2002-03-01 23:45:19 +01:00
variable to the given value. If
<replaceable>value</replaceable> is <literal>DEFAULT</literal>
or, equivalently, <literal>RESET</literal> is used, the
user-specific variable setting is removed and the user will
2002-05-17 03:19:19 +02:00
inherit the system-wide default setting in new sessions. Use
2002-03-01 23:45:19 +01:00
<literal>RESET ALL</literal> to clear all settings.
</para>
<para>
2003-03-25 17:15:44 +01:00
See <xref linkend="sql-set" endterm="sql-set-title"> and <xref linkend="runtime-config">
for more information about allowed variable names
2003-01-19 01:13:31 +01:00
and values.
2002-03-01 23:45:19 +01:00
</para>
</listitem>
</varlistentry>
1999-07-06 19:16:42 +02:00
</variablelist>
2002-02-27 22:14:54 +01:00
</refsect1>
<refsect1>
<title>Diagnostics</title>
1999-07-06 19:16:42 +02:00
2002-02-27 22:14:54 +01:00
<variablelist>
<varlistentry>
<term><computeroutput>ALTER USER</computeroutput></term>
<listitem>
<para>
Message returned if the alteration was successful.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><computeroutput>ERROR: ALTER USER: user "username" does not exist</computeroutput></term>
<listitem>
<para>
Error message returned if the specified user is not known to
2003-04-15 15:25:08 +02:00
the database system.
2002-02-27 22:14:54 +01:00
</para>
</listitem>
</varlistentry>
</variablelist>
</refsect1>
<refsect1>
<title>Notes</title>
2001-07-11 00:09:29 +02:00
<para>
2002-02-27 22:14:54 +01:00
Use <xref linkend="SQL-CREATEUSER" endterm="SQL-CREATEUSER-title">
to add new users, and <xref linkend="SQL-DROPUSER"
2002-03-22 20:20:45 +01:00
endterm="SQL-DROPUSER-title"> to remove a user.
1999-07-06 19:16:42 +02:00
</para>
2002-02-27 22:14:54 +01:00
2001-07-11 00:09:29 +02:00
<para>
<command>ALTER USER</command> cannot change a user's group memberships.
Use <xref linkend="SQL-ALTERGROUP" endterm="SQL-ALTERGROUP-title">
to do that.
</para>
2002-03-01 23:45:19 +01:00
<para>
Using <xref linkend="sql-alterdatabase"
endterm="sql-alterdatabase-title">, it is also possible to tie a
session default to a specific database rather than a user.
</para>
1999-07-06 19:16:42 +02:00
</refsect1>
2002-02-27 22:14:54 +01:00
<refsect1>
<title>Examples</title>
1999-07-06 19:16:42 +02:00
<para>
Change a user password:
2000-01-14 23:11:38 +01:00
<programlisting>
ALTER USER davide WITH PASSWORD 'hu8jmn3';
</programlisting>
2002-02-27 22:14:54 +01:00
</para>
1999-07-06 19:16:42 +02:00
2002-02-27 22:14:54 +01:00
<para>
2000-07-22 04:39:10 +02:00
Change a user's valid until date:
1999-07-06 19:16:42 +02:00
2000-01-14 23:11:38 +01:00
<programlisting>
1998-09-16 16:43:12 +02:00
ALTER USER manuel VALID UNTIL 'Jan 31 2030';
2000-01-14 23:11:38 +01:00
</programlisting>
2002-02-27 22:14:54 +01:00
</para>
1999-07-06 19:16:42 +02:00
2002-02-27 22:14:54 +01:00
<para>
1999-07-06 19:16:42 +02:00
Change a user's valid until date, specifying that his
2003-04-15 15:25:08 +02:00
authorization should expire at midday on 4th May 2005 using
2002-09-21 20:32:54 +02:00
the time zone which is one hour ahead of <acronym>UTC</>:
2000-01-14 23:11:38 +01:00
<programlisting>
2003-04-15 15:25:08 +02:00
ALTER USER chris VALID UNTIL 'May 4 12:00:00 2005 +1';
2000-01-14 23:11:38 +01:00
</programlisting>
2002-02-27 22:14:54 +01:00
</para>
1999-07-06 19:16:42 +02:00
2003-03-20 21:05:32 +01:00
<para>
Make a user valid forever:
<programlisting>
ALTER USER fred VALID UNTIL 'infinity';
</programlisting>
</para>
2002-02-27 22:14:54 +01:00
<para>
2000-07-22 04:39:10 +02:00
Give a user the ability to create other users and new databases:
1999-07-06 19:16:42 +02:00
2000-01-14 23:11:38 +01:00
<programlisting>
1998-09-16 16:43:12 +02:00
ALTER USER miriam CREATEUSER CREATEDB;
2000-01-14 23:11:38 +01:00
</programlisting>
1999-07-06 19:16:42 +02:00
</para>
</refsect1>
2002-02-27 22:14:54 +01:00
<refsect1>
<title>Compatibility</title>
1998-05-13 07:34:00 +02:00
2002-02-27 22:14:54 +01:00
<para>
The <command>ALTER USER</command> statement is a
<productname>PostgreSQL</productname> extension. The SQL standard
leaves the definition of users to the implementation.
</para>
</refsect1>
<refsect1>
<title>See Also</title>
<simplelist type="inline">
<member><xref linkend="sql-createuser" endterm="sql-createuser-title"></member>
<member><xref linkend="sql-dropuser" endterm="sql-dropuser-title"></member>
2002-03-01 23:45:19 +01:00
<member><xref linkend="sql-set" endterm="sql-set-title"></member>
2002-02-27 22:14:54 +01:00
</simplelist>
1999-07-06 19:16:42 +02:00
</refsect1>
</refentry>
1998-05-13 07:34:00 +02:00
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
1999-06-14 09:37:05 +02:00
sgml-omittag:nil
1998-05-13 07:34:00 +02:00
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
sgml-parent-document:nil
sgml-default-dtd-file:"../reference.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:"/usr/lib/sgml/catalog"
sgml-local-ecat-files:nil
End:
-->