1CREATE ROLE(7)          PostgreSQL 9.2.24 Documentation         CREATE ROLE(7)
2
3
4

NAME

6       CREATE_ROLE - define a new database role
7

SYNOPSIS

9       CREATE ROLE name [ [ WITH ] option [ ... ] ]
10
11       where option can be:
12
13             SUPERUSER | NOSUPERUSER
14           | CREATEDB | NOCREATEDB
15           | CREATEROLE | NOCREATEROLE
16           | CREATEUSER | NOCREATEUSER
17           | INHERIT | NOINHERIT
18           | LOGIN | NOLOGIN
19           | REPLICATION | NOREPLICATION
20           | CONNECTION LIMIT connlimit
21           | [ ENCRYPTED | UNENCRYPTED ] PASSWORD 'password'
22           | VALID UNTIL 'timestamp'
23           | IN ROLE role_name [, ...]
24           | IN GROUP role_name [, ...]
25           | ROLE role_name [, ...]
26           | ADMIN role_name [, ...]
27           | USER role_name [, ...]
28           | SYSID uid
29

DESCRIPTION

31       CREATE ROLE adds a new role to a PostgreSQL database cluster. A role is
32       an entity that can own database objects and have database privileges; a
33       role can be considered a “user”, a “group”, or both depending on how it
34       is used. Refer to Chapter 20, Database Roles, in the documentation and
35       Chapter 19, Client Authentication, in the documentation for information
36       about managing users and authentication. You must have CREATEROLE
37       privilege or be a database superuser to use this command.
38
39       Note that roles are defined at the database cluster level, and so are
40       valid in all databases in the cluster.
41

PARAMETERS

43       name
44           The name of the new role.
45
46       SUPERUSER, NOSUPERUSER
47           These clauses determine whether the new role is a “superuser”, who
48           can override all access restrictions within the database. Superuser
49           status is dangerous and should be used only when really needed. You
50           must yourself be a superuser to create a new superuser. If not
51           specified, NOSUPERUSER is the default.
52
53       CREATEDB, NOCREATEDB
54           These clauses define a role's ability to create databases. If
55           CREATEDB is specified, the role being defined will be allowed to
56           create new databases. Specifying NOCREATEDB will deny a role the
57           ability to create databases. If not specified, NOCREATEDB is the
58           default.
59
60       CREATEROLE, NOCREATEROLE
61           These clauses determine whether a role will be permitted to create
62           new roles (that is, execute CREATE ROLE). A role with CREATEROLE
63           privilege can also alter and drop other roles. If not specified,
64           NOCREATEROLE is the default.
65
66       CREATEUSER, NOCREATEUSER
67           These clauses are an obsolete, but still accepted, spelling of
68           SUPERUSER and NOSUPERUSER. Note that they are not equivalent to
69           CREATEROLE as one might naively expect!
70
71       INHERIT, NOINHERIT
72           These clauses determine whether a role “inherits” the privileges of
73           roles it is a member of. A role with the INHERIT attribute can
74           automatically use whatever database privileges have been granted to
75           all roles it is directly or indirectly a member of. Without
76           INHERIT, membership in another role only grants the ability to SET
77           ROLE to that other role; the privileges of the other role are only
78           available after having done so. If not specified, INHERIT is the
79           default.
80
81       LOGIN, NOLOGIN
82           These clauses determine whether a role is allowed to log in; that
83           is, whether the role can be given as the initial session
84           authorization name during client connection. A role having the
85           LOGIN attribute can be thought of as a user. Roles without this
86           attribute are useful for managing database privileges, but are not
87           users in the usual sense of the word. If not specified, NOLOGIN is
88           the default, except when CREATE ROLE is invoked through its
89           alternative spelling CREATE USER (CREATE_USER(7)).
90
91       REPLICATION, NOREPLICATION
92           These clauses determine whether a role is allowed to initiate
93           streaming replication or put the system in and out of backup mode.
94           A role having the REPLICATION attribute is a very highly privileged
95           role, and should only be used on roles actually used for
96           replication. If not specified, NOREPLICATION is the default.
97
98       CONNECTION LIMIT connlimit
99           If role can log in, this specifies how many concurrent connections
100           the role can make. -1 (the default) means no limit.
101
102       PASSWORD password
103           Sets the role's password. (A password is only of use for roles
104           having the LOGIN attribute, but you can nonetheless define one for
105           roles without it.) If you do not plan to use password
106           authentication you can omit this option. If no password is
107           specified, the password will be set to null and password
108           authentication will always fail for that user. A null password can
109           optionally be written explicitly as PASSWORD NULL.
110
111       ENCRYPTED, UNENCRYPTED
112           These key words control whether the password is stored encrypted in
113           the system catalogs. (If neither is specified, the default behavior
114           is determined by the configuration parameter password_encryption.)
115           If the presented password string is already in MD5-encrypted
116           format, then it is stored encrypted as-is, regardless of whether
117           ENCRYPTED or UNENCRYPTED is specified (since the system cannot
118           decrypt the specified encrypted password string). This allows
119           reloading of encrypted passwords during dump/restore.
120
121       VALID UNTIL 'timestamp'
122           The VALID UNTIL clause sets a date and time after which the role's
123           password is no longer valid. If this clause is omitted the password
124           will be valid for all time.
125
126       IN ROLE role_name
127           The IN ROLE clause lists one or more existing roles to which the
128           new role will be immediately added as a new member. (Note that
129           there is no option to add the new role as an administrator; use a
130           separate GRANT command to do that.)
131
132       IN GROUP role_name
133           IN GROUP is an obsolete spelling of IN ROLE.
134
135       ROLE role_name
136           The ROLE clause lists one or more existing roles which are
137           automatically added as members of the new role. (This in effect
138           makes the new role a “group”.)
139
140       ADMIN role_name
141           The ADMIN clause is like ROLE, but the named roles are added to the
142           new role WITH ADMIN OPTION, giving them the right to grant
143           membership in this role to others.
144
145       USER role_name
146           The USER clause is an obsolete spelling of the ROLE clause.
147
148       SYSID uid
149           The SYSID clause is ignored, but is accepted for backwards
150           compatibility.
151

NOTES

153       Use ALTER ROLE (ALTER_ROLE(7)) to change the attributes of a role, and
154       DROP ROLE (DROP_ROLE(7)) to remove a role. All the attributes specified
155       by CREATE ROLE can be modified by later ALTER ROLE commands.
156
157       The preferred way to add and remove members of roles that are being
158       used as groups is to use GRANT(7) and REVOKE(7).
159
160       The VALID UNTIL clause defines an expiration time for a password only,
161       not for the role per se. In particular, the expiration time is not
162       enforced when logging in using a non-password-based authentication
163       method.
164
165       The INHERIT attribute governs inheritance of grantable privileges (that
166       is, access privileges for database objects and role memberships). It
167       does not apply to the special role attributes set by CREATE ROLE and
168       ALTER ROLE. For example, being a member of a role with CREATEDB
169       privilege does not immediately grant the ability to create databases,
170       even if INHERIT is set; it would be necessary to become that role via
171       SET ROLE (SET_ROLE(7)) before creating a database.
172
173       The INHERIT attribute is the default for reasons of backwards
174       compatibility: in prior releases of PostgreSQL, users always had access
175       to all privileges of groups they were members of. However, NOINHERIT
176       provides a closer match to the semantics specified in the SQL standard.
177
178       Be careful with the CREATEROLE privilege. There is no concept of
179       inheritance for the privileges of a CREATEROLE-role. That means that
180       even if a role does not have a certain privilege but is allowed to
181       create other roles, it can easily create another role with different
182       privileges than its own (except for creating roles with superuser
183       privileges). For example, if the role “user” has the CREATEROLE
184       privilege but not the CREATEDB privilege, nonetheless it can create a
185       new role with the CREATEDB privilege. Therefore, regard roles that have
186       the CREATEROLE privilege as almost-superuser-roles.
187
188       PostgreSQL includes a program createuser(1) that has the same
189       functionality as CREATE ROLE (in fact, it calls this command) but can
190       be run from the command shell.
191
192       The CONNECTION LIMIT option is only enforced approximately; if two new
193       sessions start at about the same time when just one connection “slot”
194       remains for the role, it is possible that both will fail. Also, the
195       limit is never enforced for superusers.
196
197       Caution must be exercised when specifying an unencrypted password with
198       this command. The password will be transmitted to the server in
199       cleartext, and it might also be logged in the client's command history
200       or the server log. The command createuser(1), however, transmits the
201       password encrypted. Also, psql(1) contains a command \password that can
202       be used to safely change the password later.
203

EXAMPLES

205       Create a role that can log in, but don't give it a password:
206
207           CREATE ROLE jonathan LOGIN;
208
209       Create a role with a password:
210
211           CREATE USER davide WITH PASSWORD 'jw8s0F4';
212
213       (CREATE USER is the same as CREATE ROLE except that it implies LOGIN.)
214
215       Create a role with a password that is valid until the end of 2004.
216       After one second has ticked in 2005, the password is no longer valid.
217
218           CREATE ROLE miriam WITH LOGIN PASSWORD 'jw8s0F4' VALID UNTIL '2005-01-01';
219
220       Create a role that can create databases and manage roles:
221
222           CREATE ROLE admin WITH CREATEDB CREATEROLE;
223

COMPATIBILITY

225       The CREATE ROLE statement is in the SQL standard, but the standard only
226       requires the syntax
227
228           CREATE ROLE name [ WITH ADMIN role_name ]
229
230       Multiple initial administrators, and all the other options of CREATE
231       ROLE, are PostgreSQL extensions.
232
233       The SQL standard defines the concepts of users and roles, but it
234       regards them as distinct concepts and leaves all commands defining
235       users to be specified by each database implementation. In PostgreSQL we
236       have chosen to unify users and roles into a single kind of entity.
237       Roles therefore have many more optional attributes than they do in the
238       standard.
239
240       The behavior specified by the SQL standard is most closely approximated
241       by giving users the NOINHERIT attribute, while roles are given the
242       INHERIT attribute.
243

SEE ALSO

245       SET ROLE (SET_ROLE(7)), ALTER ROLE (ALTER_ROLE(7)), DROP ROLE
246       (DROP_ROLE(7)), GRANT(7), REVOKE(7), createuser(1)
247
248
249
250PostgreSQL 9.2.24                 2017-11-06                    CREATE ROLE(7)
Impressum