1CREATE ROLE(7)           PostgreSQL 15.4 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           | INHERIT | NOINHERIT
17           | LOGIN | NOLOGIN
18           | REPLICATION | NOREPLICATION
19           | BYPASSRLS | NOBYPASSRLS
20           | CONNECTION LIMIT connlimit
21           | [ ENCRYPTED ] PASSWORD 'password' | PASSWORD NULL
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 22 and Chapter 21 for information about
35       managing users and authentication. You must have CREATEROLE privilege
36       or be a database superuser to use this command.
37
38       Note that roles are defined at the database cluster level, and so are
39       valid in all databases in the cluster.
40

PARAMETERS

42       name
43           The name of the new role.
44
45       SUPERUSER
46       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
54       NOCREATEDB
55           These clauses define a role's ability to create databases. If
56           CREATEDB is specified, the role being defined will be allowed to
57           create new databases. Specifying NOCREATEDB will deny a role the
58           ability to create databases. If not specified, NOCREATEDB is the
59           default.
60
61       CREATEROLE
62       NOCREATEROLE
63           These clauses determine whether a role will be permitted to create,
64           alter, drop, comment on, change the security label for, and grant
65           or revoke membership in other roles. See role creation for more
66           details about what capabilities are conferred by this privilege. If
67           not specified, NOCREATEROLE is the default.
68
69       INHERIT
70       NOINHERIT
71           These clauses determine whether a role “inherits” the privileges of
72           roles it is a member of. A role with the INHERIT attribute can
73           automatically use whatever database privileges have been granted to
74           all roles it is directly or indirectly a member of. Without
75           INHERIT, membership in another role only grants the ability to SET
76           ROLE to that other role; the privileges of the other role are only
77           available after having done so. If not specified, INHERIT is the
78           default.
79
80       LOGIN
81       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.
90
91       REPLICATION
92       NOREPLICATION
93           These clauses determine whether a role is a replication role. A
94           role must have this attribute (or be a superuser) in order to be
95           able to connect to the server in replication mode (physical or
96           logical replication) and in order to be able to create or drop
97           replication slots. A role having the REPLICATION attribute is a
98           very highly privileged role, and should only be used on roles
99           actually used for replication. If not specified, NOREPLICATION is
100           the default. You must be a superuser to create a new role having
101           the REPLICATION attribute.
102
103       BYPASSRLS
104       NOBYPASSRLS
105           These clauses determine whether a role bypasses every row-level
106           security (RLS) policy.  NOBYPASSRLS is the default. You must be a
107           superuser to create a new role having the BYPASSRLS attribute.
108
109           Note that pg_dump will set row_security to OFF by default, to
110           ensure all contents of a table are dumped out. If the user running
111           pg_dump does not have appropriate permissions, an error will be
112           returned. However, superusers and the owner of the table being
113           dumped always bypass RLS.
114
115       CONNECTION LIMIT connlimit
116           If role can log in, this specifies how many concurrent connections
117           the role can make. -1 (the default) means no limit. Note that only
118           normal connections are counted towards this limit. Neither prepared
119           transactions nor background worker connections are counted towards
120           this limit.
121
122       [ ENCRYPTED ] PASSWORD 'password'
123       PASSWORD NULL
124           Sets the role's password. (A password is only of use for roles
125           having the LOGIN attribute, but you can nonetheless define one for
126           roles without it.) If you do not plan to use password
127           authentication you can omit this option. If no password is
128           specified, the password will be set to null and password
129           authentication will always fail for that user. A null password can
130           optionally be written explicitly as PASSWORD NULL.
131
132               Note
133               Specifying an empty string will also set the password to null,
134               but that was not the case before PostgreSQL version 10. In
135               earlier versions, an empty string could be used, or not,
136               depending on the authentication method and the exact version,
137               and libpq would refuse to use it in any case. To avoid the
138               ambiguity, specifying an empty string should be avoided.
139           The password is always stored encrypted in the system catalogs. The
140           ENCRYPTED keyword has no effect, but is accepted for backwards
141           compatibility. The method of encryption is determined by the
142           configuration parameter password_encryption. If the presented
143           password string is already in MD5-encrypted or SCRAM-encrypted
144           format, then it is stored as-is regardless of password_encryption
145           (since the system cannot decrypt the specified encrypted password
146           string, to encrypt it in a different format). This allows reloading
147           of encrypted passwords during dump/restore.
148
149       VALID UNTIL 'timestamp'
150           The VALID UNTIL clause sets a date and time after which the role's
151           password is no longer valid. If this clause is omitted the password
152           will be valid for all time.
153
154       IN ROLE role_name
155           The IN ROLE clause lists one or more existing roles to which the
156           new role will be immediately added as a new member. (Note that
157           there is no option to add the new role as an administrator; use a
158           separate GRANT command to do that.)
159
160       IN GROUP role_name
161           IN GROUP is an obsolete spelling of IN ROLE.
162
163       ROLE role_name
164           The ROLE clause lists one or more existing roles which are
165           automatically added as members of the new role. (This in effect
166           makes the new role a “group”.)
167
168       ADMIN role_name
169           The ADMIN clause is like ROLE, but the named roles are added to the
170           new role WITH ADMIN OPTION, giving them the right to grant
171           membership in this role to others.
172
173       USER role_name
174           The USER clause is an obsolete spelling of the ROLE clause.
175
176       SYSID uid
177           The SYSID clause is ignored, but is accepted for backwards
178           compatibility.
179

NOTES

181       Use ALTER ROLE to change the attributes of a role, and DROP ROLE to
182       remove a role. All the attributes specified by CREATE ROLE can be
183       modified by later ALTER ROLE commands.
184
185       The preferred way to add and remove members of roles that are being
186       used as groups is to use GRANT and REVOKE.
187
188       The VALID UNTIL clause defines an expiration time for a password only,
189       not for the role per se. In particular, the expiration time is not
190       enforced when logging in using a non-password-based authentication
191       method.
192
193       The INHERIT attribute governs inheritance of grantable privileges (that
194       is, access privileges for database objects and role memberships). It
195       does not apply to the special role attributes set by CREATE ROLE and
196       ALTER ROLE. For example, being a member of a role with CREATEDB
197       privilege does not immediately grant the ability to create databases,
198       even if INHERIT is set; it would be necessary to become that role via
199       SET ROLE before creating a database.
200
201       The INHERIT attribute is the default for reasons of backwards
202       compatibility: in prior releases of PostgreSQL, users always had access
203       to all privileges of groups they were members of. However, NOINHERIT
204       provides a closer match to the semantics specified in the SQL standard.
205
206       Be careful with the CREATEROLE privilege. There is no concept of
207       inheritance for the privileges of a CREATEROLE-role. That means that
208       even if a role does not have a certain privilege but is allowed to
209       create other roles, it can easily create another role with different
210       privileges than its own (except for creating roles with superuser
211       privileges). For example, if the role “user” has the CREATEROLE
212       privilege but not the CREATEDB privilege, nonetheless it can create a
213       new role with the CREATEDB privilege. Therefore, regard roles that have
214       the CREATEROLE privilege as almost-superuser-roles.
215
216       PostgreSQL includes a program createuser(1) that has the same
217       functionality as CREATE ROLE (in fact, it calls this command) but can
218       be run from the command shell.
219
220       The CONNECTION LIMIT option is only enforced approximately; if two new
221       sessions start at about the same time when just one connection “slot”
222       remains for the role, it is possible that both will fail. Also, the
223       limit is never enforced for superusers.
224
225       Caution must be exercised when specifying an unencrypted password with
226       this command. The password will be transmitted to the server in
227       cleartext, and it might also be logged in the client's command history
228       or the server log. The command createuser(1), however, transmits the
229       password encrypted. Also, psql(1) contains a command \password that can
230       be used to safely change the password later.
231

EXAMPLES

233       Create a role that can log in, but don't give it a password:
234
235           CREATE ROLE jonathan LOGIN;
236
237       Create a role with a password:
238
239           CREATE USER davide WITH PASSWORD 'jw8s0F4';
240
241       (CREATE USER is the same as CREATE ROLE except that it implies LOGIN.)
242
243       Create a role with a password that is valid until the end of 2004.
244       After one second has ticked in 2005, the password is no longer valid.
245
246           CREATE ROLE miriam WITH LOGIN PASSWORD 'jw8s0F4' VALID UNTIL '2005-01-01';
247
248       Create a role that can create databases and manage roles:
249
250           CREATE ROLE admin WITH CREATEDB CREATEROLE;
251

COMPATIBILITY

253       The CREATE ROLE statement is in the SQL standard, but the standard only
254       requires the syntax
255
256           CREATE ROLE name [ WITH ADMIN role_name ]
257
258       Multiple initial administrators, and all the other options of CREATE
259       ROLE, are PostgreSQL extensions.
260
261       The SQL standard defines the concepts of users and roles, but it
262       regards them as distinct concepts and leaves all commands defining
263       users to be specified by each database implementation. In PostgreSQL we
264       have chosen to unify users and roles into a single kind of entity.
265       Roles therefore have many more optional attributes than they do in the
266       standard.
267
268       The behavior specified by the SQL standard is most closely approximated
269       by giving users the NOINHERIT attribute, while roles are given the
270       INHERIT attribute.
271

SEE ALSO

273       SET ROLE (SET_ROLE(7)), ALTER ROLE (ALTER_ROLE(7)), DROP ROLE
274       (DROP_ROLE(7)), GRANT(7), REVOKE(7), createuser(1)
275
276
277
278PostgreSQL 15.4                      2023                       CREATE ROLE(7)
Impressum