ALTER USER

Name

ALTER USER  --  Modifies user account information

Synopsis

ALTER USER username
    [ WITH PASSWORD 'password' ]
    [ CREATEDB | NOCREATEDB ] [ CREATEUSER | NOCREATEUSER ]
    [ VALID UNTIL 'abstime' ]
  

Inputs

username

The name of the user whose details are to be altered.

password

The new password to be used for this account.

CREATEDB, NOCREATEDB

These clauses establish the user's ability to create databases. If CREATEDB is specified, the user being defined will be allowed to create his own databases. NOCREATEDB will deny the user the ability to create databases.

CREATEUSER, NOCREATEUSER

These clauses determine whether a user will be permitted to create new users himself. This option will also make the user a superuser that can override all access restrictions.

abstime

The date (and, optionally, the time) at which this user's password will expire.

Outputs

ALTER USER

Message returned if the alteration was successful.

ERROR: ALTER USER: user "username" does not exist

Error message returned if the specified user is not known to the database.

Description

ALTER USER is used to change the attributes of a user's PostgreSQL account. Only a database superuser can change privileges and password expiration with this command. Ordinary users can only change their own password.

Use CREATE USER to create a new user and DROP USER to remove a user.

Usage

To create a user
CREATE USER rhdb1;

Change a user password:
ALTER USER rhdb1 WITH PASSWORD 'ke2fv9a';
Change a user's valid until date:
ALTER USER rhdb1 VALID UNTIL 'Dec 31 2050';
Give a user the ability to create other users and new databases:
ALTER USER rhdb1 CREATEDB;
To change a user's valid until date to be December 31 2099 at midday, using the timezone that is 4 hours behind UTC:
ALTER USER rhdb1 VALID UNTIL 'Dec 31 12:00:00 2099 -4';

Compatibility

SQL92

There is no ALTER USER statement in SQL92.