1CREATEUSER(1)            PostgreSQL 16.1 Documentation           CREATEUSER(1)
2
3
4

NAME

6       createuser - define a new PostgreSQL user account
7

SYNOPSIS

9       createuser [connection-option...] [option...] [username]
10

DESCRIPTION

12       createuser creates a new PostgreSQL user (or more precisely, a role).
13       Only superusers and users with CREATEROLE privilege can create new
14       users, so createuser must be invoked by someone who can connect as a
15       superuser or a user with CREATEROLE privilege.
16
17       If you wish to create a role with the SUPERUSER, REPLICATION, or
18       BYPASSRLS privilege, you must connect as a superuser, not merely with
19       CREATEROLE privilege. Being a superuser implies the ability to bypass
20       all access permission checks within the database, so superuser access
21       should not be granted lightly.  CREATEROLE also conveys very extensive
22       privileges.
23
24       createuser is a wrapper around the SQL command CREATE ROLE. There is no
25       effective difference between creating users via this utility and via
26       other methods for accessing the server.
27

OPTIONS

29       createuser accepts the following command-line arguments:
30
31       username
32           Specifies the name of the PostgreSQL user to be created. This name
33           must be different from all existing roles in this PostgreSQL
34           installation.
35
36       -a role
37       --with-admin=role
38           Specifies an existing role that will be automatically added as a
39           member of the new role with admin option, giving it the right to
40           grant membership in the new role to others. Multiple existing roles
41           can be specified by writing multiple -a switches.
42
43       -c number
44       --connection-limit=number
45           Set a maximum number of connections for the new user. The default
46           is to set no limit.
47
48       -d
49       --createdb
50           The new user will be allowed to create databases.
51
52       -D
53       --no-createdb
54           The new user will not be allowed to create databases. This is the
55           default.
56
57       -e
58       --echo
59           Echo the commands that createuser generates and sends to the
60           server.
61
62       -E
63       --encrypted
64           This option is obsolete but still accepted for backward
65           compatibility.
66
67       -g role
68       --member-of=role
69       --role=role (deprecated)
70           Specifies the new role should be automatically added as a member of
71           the specified existing role. Multiple existing roles can be
72           specified by writing multiple -g switches.
73
74       -i
75       --inherit
76           The new role will automatically inherit privileges of roles it is a
77           member of. This is the default.
78
79       -I
80       --no-inherit
81           The new role will not automatically inherit privileges of roles it
82           is a member of.
83
84       --interactive
85           Prompt for the user name if none is specified on the command line,
86           and also prompt for whichever of the options -d/-D, -r/-R, -s/-S is
87           not specified on the command line. (This was the default behavior
88           up to PostgreSQL 9.1.)
89
90       -l
91       --login
92           The new user will be allowed to log in (that is, the user name can
93           be used as the initial session user identifier). This is the
94           default.
95
96       -L
97       --no-login
98           The new user will not be allowed to log in. (A role without login
99           privilege is still useful as a means of managing database
100           permissions.)
101
102       -m role
103       --with-member=role
104           Specifies an existing role that will be automatically added as a
105           member of the new role. Multiple existing roles can be specified by
106           writing multiple -m switches.
107
108       -P
109       --pwprompt
110           If given, createuser will issue a prompt for the password of the
111           new user. This is not necessary if you do not plan on using
112           password authentication.
113
114       -r
115       --createrole
116           The new user will be allowed to create, alter, drop, comment on,
117           change the security label for other roles; that is, this user will
118           have CREATEROLE privilege. See role creation for more details about
119           what capabilities are conferred by this privilege.
120
121       -R
122       --no-createrole
123           The new user will not be allowed to create new roles. This is the
124           default.
125
126       -s
127       --superuser
128           The new user will be a superuser.
129
130       -S
131       --no-superuser
132           The new user will not be a superuser. This is the default.
133
134       -v timestamp
135       --valid-until=timestamp
136           Set a date and time after which the role's password is no longer
137           valid. The default is to set no password expiry date.
138
139       -V
140       --version
141           Print the createuser version and exit.
142
143       --bypassrls
144           The new user will bypass every row-level security (RLS) policy.
145
146       --no-bypassrls
147           The new user will not bypass row-level security (RLS) policies.
148           This is the default.
149
150       --replication
151           The new user will have the REPLICATION privilege, which is
152           described more fully in the documentation for CREATE ROLE
153           (CREATE_ROLE(7)).
154
155       --no-replication
156           The new user will not have the REPLICATION privilege, which is
157           described more fully in the documentation for CREATE ROLE
158           (CREATE_ROLE(7)). This is the default.
159
160       -?
161       --help
162           Show help about createuser command line arguments, and exit.
163
164       createuser also accepts the following command-line arguments for
165       connection parameters:
166
167       -h host
168       --host=host
169           Specifies the host name of the machine on which the server is
170           running. If the value begins with a slash, it is used as the
171           directory for the Unix domain socket.
172
173       -p port
174       --port=port
175           Specifies the TCP port or local Unix domain socket file extension
176           on which the server is listening for connections.
177
178       -U username
179       --username=username
180           User name to connect as (not the user name to create).
181
182       -w
183       --no-password
184           Never issue a password prompt. If the server requires password
185           authentication and a password is not available by other means such
186           as a .pgpass file, the connection attempt will fail. This option
187           can be useful in batch jobs and scripts where no user is present to
188           enter a password.
189
190       -W
191       --password
192           Force createuser to prompt for a password (for connecting to the
193           server, not for the password of the new user).
194
195           This option is never essential, since createuser will automatically
196           prompt for a password if the server demands password
197           authentication. However, createuser will waste a connection attempt
198           finding out that the server wants a password. In some cases it is
199           worth typing -W to avoid the extra connection attempt.
200

ENVIRONMENT

202       PGHOST
203       PGPORT
204       PGUSER
205           Default connection parameters
206
207       PG_COLOR
208           Specifies whether to use color in diagnostic messages. Possible
209           values are always, auto and never.
210
211       This utility, like most other PostgreSQL utilities, also uses the
212       environment variables supported by libpq (see Section 34.15).
213

DIAGNOSTICS

215       In case of difficulty, see CREATE ROLE (CREATE_ROLE(7)) and psql(1) for
216       discussions of potential problems and error messages. The database
217       server must be running at the targeted host. Also, any default
218       connection settings and environment variables used by the libpq
219       front-end library will apply.
220

EXAMPLES

222       To create a user joe on the default database server:
223
224           $ createuser joe
225
226       To create a user joe on the default database server with prompting for
227       some additional attributes:
228
229           $ createuser --interactive joe
230           Shall the new role be a superuser? (y/n) n
231           Shall the new role be allowed to create databases? (y/n) n
232           Shall the new role be allowed to create more new roles? (y/n) n
233
234       To create the same user joe using the server on host eden, port 5000,
235       with attributes explicitly specified, taking a look at the underlying
236       command:
237
238           $ createuser -h eden -p 5000 -S -D -R -e joe
239           CREATE ROLE joe NOSUPERUSER NOCREATEDB NOCREATEROLE INHERIT LOGIN;
240
241       To create the user joe as a superuser, and assign a password
242       immediately:
243
244           $ createuser -P -s -e joe
245           Enter password for new role: xyzzy
246           Enter it again: xyzzy
247           CREATE ROLE joe PASSWORD 'md5b5f5ba1a423792b526f799ae4eb3d59e' SUPERUSER CREATEDB CREATEROLE INHERIT LOGIN;
248
249       In the above example, the new password isn't actually echoed when
250       typed, but we show what was typed for clarity. As you see, the password
251       is encrypted before it is sent to the client.
252

SEE ALSO

254       dropuser(1), CREATE ROLE (CREATE_ROLE(7)), createrole_self_grant
255
256
257
258PostgreSQL 16.1                      2023                        CREATEUSER(1)
Impressum