CREATE USER
SQL - Language Statements
CREATE USER
Creates account information for a new user
1999-07-20
CREATE USER username
[ WITH
[ SYSID uid ]
[ PASSWORD password ] ]
[ CREATEDB | NOCREATEDB ] [ CREATEUSER | NOCREATEUSER ]
[ IN GROUP groupname [, ...] ]
[ VALID UNTIL 'abstime' ]
1998-09-21
Inputs
username
The name of the user.
uid
The SYSID clause can be used to choose
the PostgreSQL user id of the user
that is being created. It is not at all necessary that those
match the UNIX user ids, but some people
choose to keep the numbers the same.
If this is not specified, the highest assigned user id plus one
will be used as default.
password
The PASSWORD clause sets the user's password within
the "pg_shadow" table. For this reason,
"pg_shadow" is no
longer accessible to the instance of
Postgres that the
Postgres
user's password is initially set to NULL.
When a
user's password in the "pg_shadow"
table is NULL, user
authentication proceeds as it historically has (HBA,
PG_PASSWORD, etc). However, if a password is set for a
user, a new authentication system supplants any other
configured for the Postgres
instance, and the password
stored in the "pg_shadow" table is used
for authentication.
For more details on how this authentication system
functions see pg_crypt(3). If the WITH PASSWORD clause is
omitted, the user's password is set to the empty
string which equates to a NULL value in the authentication
system mentioned above.
CREATEDB
NOCREATEDB
These clauses define a user's ability to create databases.
If CREATEDB is specified, the user being defined will
be allowed to create his own databases. Using NOCREATEDB
will deny a user the ability to create databases. If this
clause is omitted, NOCREATEDB is used by default.
CREATEUSER
NOCREATEUSER
These clauses determine whether a user will be permitted to
create new
users in an instance of Postgres.
Omitting this clause will set the user's value of this
attribute to be NOCREATEUSER.
groupname
A name of a group into which to insert the user as a new member.
abstime
The VALID UNTIL clause sets an absolute time after which the
user's Postgres
login is no longer valid. Please note that
if a user does not have a password defined in the
"pg_shadow"
table, the valid until date will not be checked
during user authentication. If this clause is omitted,
a NULL value is stored in "pg_shadow"
for this attribute,
and the login will be valid for all time.
1998-09-21
Outputs
CREATE USER
Message returned if the command completes successfully.
1998-09-21
Description
CREATE USER will add a new user to an instance of
PostgreSQL.
1998-09-21
Notes
CREATE USER statement is a
Postgres language extension.
Use DROP USER or ALTER USER
statements to remove or modify a user account.
Refer to the pg_shadow table for further information.
Table "pg_shadow"
Attribute | Type | Extra
-------------+---------+-------
usename | name |
usesysid | int4 |
usecreatedb | bool |
usetrace | bool |
usesuper | bool |
usecatupd | bool |
passwd | text |
valuntil | abstime |
Usage
Create a user with no password:
CREATE USER jonathan
Create a user with a password:
CREATE USER davide WITH PASSWORD "jw8s0F4"
Create a user with a password, whose account is valid until the end of 2001.
Note that after one second has ticked in 2002, the account is not
valid:
CREATE USER miriam WITH PASSWORD "jw8s0F4" VALID UNTIL 'Jan 1 2002'
Create an account where the user can create databases:
CREATE USER manuel WITH PASSWORD "jw8s0F4" CREATEDB
Compatibility
1998-09-21
SQL92
There is no CREATE USER statement in SQL92.