3
.\" Author: The PostgreSQL Global Development Group
4
.\" Generator: DocBook XSL Stylesheets v1.75.1 <http://docbook.sf.net/>
6
.\" Manual: PostgreSQL 9.1beta1 Documentation
7
.\" Source: PostgreSQL 9.1beta1
10
.TH "CREATE ROLE" "7" "2011-04-27" "PostgreSQL 9.1beta1" "PostgreSQL 9.1beta1 Documentation"
11
.\" -----------------------------------------------------------------
12
.\" * set default formatting
13
.\" -----------------------------------------------------------------
14
.\" disable hyphenation
16
.\" disable justification (adjust text to left margin only)
18
.\" -----------------------------------------------------------------
19
.\" * MAIN CONTENT STARTS HERE *
20
.\" -----------------------------------------------------------------
22
CREATE_ROLE \- define a new database role
27
CREATE ROLE \fIname\fR [ [ WITH ] \fIoption\fR [ \&.\&.\&. ] ]
29
where \fIoption\fR can be:
31
SUPERUSER | NOSUPERUSER
32
| CREATEDB | NOCREATEDB
33
| CREATEROLE | NOCREATEROLE
34
| CREATEUSER | NOCREATEUSER
37
| REPLICATION | NOREPLICATION
38
| CONNECTION LIMIT \fIconnlimit\fR
39
| [ ENCRYPTED | UNENCRYPTED ] PASSWORD \(aq\fIpassword\fR\(aq
40
| VALID UNTIL \(aq\fItimestamp\fR\(aq
41
| IN ROLE \fIrole_name\fR [, \&.\&.\&.]
42
| IN GROUP \fIrole_name\fR [, \&.\&.\&.]
43
| ROLE \fIrole_name\fR [, \&.\&.\&.]
44
| ADMIN \fIrole_name\fR [, \&.\&.\&.]
45
| USER \fIrole_name\fR [, \&.\&.\&.]
53
database cluster\&. A role is an entity that can own database objects and have database privileges; a role can be considered a
55
\(lqgroup\(rq, or both depending on how it is used\&. Refer to
56
Chapter 20, Database Roles, in the documentation
58
Chapter 19, Client Authentication, in the documentation
59
for information about managing users and authentication\&. You must have
61
privilege or be a database superuser to use this command\&.
63
Note that roles are defined at the database cluster level, and so are valid in all databases in the cluster\&.
68
The name of the new role\&.
71
SUPERUSER, NOSUPERUSER
73
These clauses determine whether the new role is a
74
\(lqsuperuser\(rq, who can override all access restrictions within the database\&. Superuser status is dangerous and should be used only when really needed\&. You must yourself be a superuser to create a new superuser\&. If not specified,
81
These clauses define a role\(aqs ability to create databases\&. If
83
is specified, the role being defined will be allowed to create new databases\&. Specifying
85
will deny a role the ability to create databases\&. If not specified,
90
CREATEROLE, NOCREATEROLE
92
These clauses determine whether a role will be permitted to create new roles (that is, execute
93
CREATE ROLE)\&. A role with
95
privilege can also alter and drop other roles\&. If not specified,
100
CREATEUSER, NOCREATEUSER
102
These clauses are an obsolete, but still accepted, spelling of
105
NOSUPERUSER\&. Note that they are
109
as one might naively expect!
114
These clauses determine whether a role
116
the privileges of roles it is a member of\&. A role with the
118
attribute can automatically use whatever database privileges have been granted to all roles it is directly or indirectly a member of\&. Without
119
INHERIT, membership in another role only grants the ability to
121
to that other role; the privileges of the other role are only available after having done so\&. If not specified,
128
These clauses determine whether a role is allowed to log in; that is, whether the role can be given as the initial session authorization name during client connection\&. A role having the
130
attribute can be thought of as a user\&. Roles without this attribute are useful for managing database privileges, but are not users in the usual sense of the word\&. If not specified,
132
is the default, except when
134
is invoked through its alternative spelling
138
REPLICATION, NOREPLICATION
140
These clauses determine whether a role is allowed to initiate streaming replication or put the system in and out of backup mode\&. A role having the
142
attribute is a very highly privileged role, and should only be used on roles actually used for replication\&. If not specified,
144
is the default for all roles except superusers\&.
147
CONNECTION LIMIT \fIconnlimit\fR
149
If role can log in, this specifies how many concurrent connections the role can make\&. \-1 (the default) means no limit\&.
152
PASSWORD \fIpassword\fR
154
Sets the role\(aqs password\&. (A password is only of use for roles having the
156
attribute, but you can nonetheless define one for roles without it\&.) If you do not plan to use password authentication you can omit this option\&. If no password is specified, the password will be set to null and password authentication will always fail for that user\&. A null password can optionally be written explicitly as
160
ENCRYPTED, UNENCRYPTED
162
These key words control whether the password is stored encrypted in the system catalogs\&. (If neither is specified, the default behavior is determined by the configuration parameter
163
password_encryption\&.) If the presented password string is already in MD5\-encrypted format, then it is stored encrypted as\-is, regardless of whether
167
is specified (since the system cannot decrypt the specified encrypted password string)\&. This allows reloading of encrypted passwords during dump/restore\&.
169
Note that older clients might lack support for the MD5 authentication mechanism that is needed to work with passwords that are stored encrypted\&.
172
VALID UNTIL \(aq\fItimestamp\fR\(aq
176
clause sets a date and time after which the role\(aqs password is no longer valid\&. If this clause is omitted the password will be valid for all time\&.
179
IN ROLE \fIrole_name\fR
183
clause lists one or more existing roles to which the new role will be immediately added as a new member\&. (Note that there is no option to add the new role as an administrator; use a separate
185
command to do that\&.)
188
IN GROUP \fIrole_name\fR
191
is an obsolete spelling of
199
clause lists one or more existing roles which are automatically added as members of the new role\&. (This in effect makes the new role a
203
ADMIN \fIrole_name\fR
208
ROLE, but the named roles are added to the new role
209
WITH ADMIN OPTION, giving them the right to grant membership in this role to others\&.
216
clause is an obsolete spelling of the
225
clause is ignored, but is accepted for backwards compatibility\&.
230
ALTER ROLE (\fBALTER_ROLE\fR(7))
231
to change the attributes of a role, and
232
DROP ROLE (\fBDROP_ROLE\fR(7))
233
to remove a role\&. All the attributes specified by
235
can be modified by later
239
The preferred way to add and remove members of roles that are being used as groups is to use
246
clause defines an expiration time for a password only, not for the role
247
per se\&. In particular, the expiration time is not enforced when logging in using a non\-password\-based authentication method\&.
251
attribute governs inheritance of grantable privileges (that is, access privileges for database objects and role memberships)\&. It does not apply to the special role attributes set by
254
ALTER ROLE\&. For example, being a member of a role with
256
privilege does not immediately grant the ability to create databases, even if
258
is set; it would be necessary to become that role via
259
SET ROLE (\fBSET_ROLE\fR(7))
260
before creating a database\&.
264
attribute is the default for reasons of backwards compatibility: in prior releases of
265
PostgreSQL, users always had access to all privileges of groups they were members of\&. However,
267
provides a closer match to the semantics specified in the SQL standard\&.
271
privilege\&. There is no concept of inheritance for the privileges of a
272
CREATEROLE\-role\&. That means that even if a role does not have a certain privilege but is allowed to create other roles, it can easily create another role with different privileges than its own (except for creating roles with superuser privileges)\&. For example, if the role
276
privilege but not the
278
privilege, nonetheless it can create a new role with the
280
privilege\&. Therefore, regard roles that have the
282
privilege as almost\-superuser\-roles\&.
287
that has the same functionality as
289
(in fact, it calls this command) but can be run from the command shell\&.
293
option is only enforced approximately; if two new sessions start at about the same time when just one connection
295
remains for the role, it is possible that both will fail\&. Also, the limit is never enforced for superusers\&.
297
Caution must be exercised when specifying an unencrypted password with this command\&. The password will be transmitted to the server in cleartext, and it might also be logged in the client\(aqs command history or the server log\&. The command
298
\fBcreateuser\fR(1), however, transmits the password encrypted\&. Also,
302
that can be used to safely change the password later\&.
305
Create a role that can log in, but don\(aqt give it a password:
311
CREATE ROLE jonathan LOGIN;
317
Create a role with a password:
323
CREATE USER davide WITH PASSWORD \(aqjw8s0F4\(aq;
332
except that it implies
335
Create a role with a password that is valid until the end of 2004\&. After one second has ticked in 2005, the password is no longer valid\&.
341
CREATE ROLE miriam WITH LOGIN PASSWORD \(aqjw8s0F4\(aq VALID UNTIL \(aq2005\-01\-01\(aq;
347
Create a role that can create databases and manage roles:
353
CREATE ROLE admin WITH CREATEDB CREATEROLE;
362
statement is in the SQL standard, but the standard only requires the syntax
368
CREATE ROLE \fIname\fR [ WITH ADMIN \fIrole_name\fR ]
375
Multiple initial administrators, and all the other options of
380
The SQL standard defines the concepts of users and roles, but it regards them as distinct concepts and leaves all commands defining users to be specified by each database implementation\&. In
382
we have chosen to unify users and roles into a single kind of entity\&. Roles therefore have many more optional attributes than they do in the standard\&.
384
The behavior specified by the SQL standard is most closely approximated by giving users the
386
attribute, while roles are given the
390
SET ROLE (\fBSET_ROLE\fR(7)), ALTER ROLE (\fBALTER_ROLE\fR(7)), DROP ROLE (\fBDROP_ROLE\fR(7)), \fBGRANT\fR(7), \fBREVOKE\fR(7), \fBcreateuser\fR(1)