ALTER USERSection: SQL Commands (7)Updated: 2003-11-02 |
ALTER USERSection: SQL Commands (7)Updated: 2003-11-02 |
ALTER USER name [ [ WITH ] option [ ... ] ]
where option can be:
[ ENCRYPTED | UNENCRYPTED ] PASSWORD 'password'
| CREATEDB | NOCREATEDB
| CREATEUSER | NOCREATEUSER
| VALID UNTIL 'abstime'
ALTER USER name RENAME TO newname
ALTER USER name SET parameter { TO | = } { value | DEFAULT }
ALTER USER name RESET parameter
ALTER USER is used to change the attributes of a PostgreSQL user account. Attributes not mentioned in the command retain their previous settings.
The first variant of this command in the synopsis changes certain global user privileges and authentication settings. (See below for details.) Only a database superuser can change these privileges and the password expiration with this command. Ordinary users can only change their own password.
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.)
The third and the fourth variant change a user's session default for a specified configuration variable. Whenever the user subsequently starts a new session, the specified value becomes the session default, overriding whatever setting is present in postgresql.conf or has been received from the postmaster command line. Ordinary users can change their own session defaults. Superusers can change anyone's session defaults.
See SET [set(7)] and the section called ``Run-time Configuration'' in the documentation for more information about allowed parameter names and values.
Use CREATE USER [create_user(7)] to add new users, and DROP USER [drop_user(7)] to remove a user.
ALTER USER cannot change a user's group memberships. Use ALTER GROUP [alter_group(7)] to do that.
Using ALTER DATABASE [alter_database(7)], it is also possible to tie a session default to a specific database rather than a user.
Change a user password:
ALTER USER davide WITH PASSWORD 'hu8jmn3';
Change a user's valid until date:
ALTER USER manuel VALID UNTIL 'Jan 31 2030';
Change a user's valid until date, specifying that his authorization should expire at midday on 4th May 2005 using the time zone which is one hour ahead of UTC:
ALTER USER chris VALID UNTIL 'May 4 12:00:00 2005 +1';
Make a user valid forever:
ALTER USER fred VALID UNTIL 'infinity';
Give a user the ability to create other users and new databases:
ALTER USER miriam CREATEUSER CREATEDB;
The ALTER USER statement is a PostgreSQL extension. The SQL standard leaves the definition of users to the implementation.