1CREATEUSER(1) PostgreSQL 15.4 Documentation CREATEUSER(1)
2
3
4
6 createuser - define a new PostgreSQL user account
7
9 createuser [connection-option...] [option...] [username]
10
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
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 -c number
37 --connection-limit=number
38 Set a maximum number of connections for the new user. The default
39 is to set no limit.
40
41 -d
42 --createdb
43 The new user will be allowed to create databases.
44
45 -D
46 --no-createdb
47 The new user will not be allowed to create databases. This is the
48 default.
49
50 -e
51 --echo
52 Echo the commands that createuser generates and sends to the
53 server.
54
55 -E
56 --encrypted
57 This option is obsolete but still accepted for backward
58 compatibility.
59
60 -g role
61 --role=role
62 Indicates role to which this role will be added immediately as a
63 new member. Multiple roles to which this role will be added as a
64 member can be specified by writing multiple -g switches.
65
66 -i
67 --inherit
68 The new role will automatically inherit privileges of roles it is a
69 member of. This is the default.
70
71 -I
72 --no-inherit
73 The new role will not automatically inherit privileges of roles it
74 is a member of.
75
76 --interactive
77 Prompt for the user name if none is specified on the command line,
78 and also prompt for whichever of the options -d/-D, -r/-R, -s/-S is
79 not specified on the command line. (This was the default behavior
80 up to PostgreSQL 9.1.)
81
82 -l
83 --login
84 The new user will be allowed to log in (that is, the user name can
85 be used as the initial session user identifier). This is the
86 default.
87
88 -L
89 --no-login
90 The new user will not be allowed to log in. (A role without login
91 privilege is still useful as a means of managing database
92 permissions.)
93
94 -P
95 --pwprompt
96 If given, createuser will issue a prompt for the password of the
97 new user. This is not necessary if you do not plan on using
98 password authentication.
99
100 -r
101 --createrole
102 The new user will be allowed to create, alter, drop, comment on,
103 change the security label for, and grant or revoke membership in
104 other roles; that is, this user will have CREATEROLE privilege. See
105 role creation for more details about what capabilities are
106 conferred by this privilege.
107
108 -R
109 --no-createrole
110 The new user will not be allowed to create new roles. This is the
111 default.
112
113 -s
114 --superuser
115 The new user will be a superuser.
116
117 -S
118 --no-superuser
119 The new user will not be a superuser. This is the default.
120
121 -V
122 --version
123 Print the createuser version and exit.
124
125 --replication
126 The new user will have the REPLICATION privilege, which is
127 described more fully in the documentation for CREATE ROLE
128 (CREATE_ROLE(7)).
129
130 --no-replication
131 The new user will not have the REPLICATION privilege, which is
132 described more fully in the documentation for CREATE ROLE
133 (CREATE_ROLE(7)).
134
135 -?
136 --help
137 Show help about createuser command line arguments, and exit.
138
139 createuser also accepts the following command-line arguments for
140 connection parameters:
141
142 -h host
143 --host=host
144 Specifies the host name of the machine on which the server is
145 running. If the value begins with a slash, it is used as the
146 directory for the Unix domain socket.
147
148 -p port
149 --port=port
150 Specifies the TCP port or local Unix domain socket file extension
151 on which the server is listening for connections.
152
153 -U username
154 --username=username
155 User name to connect as (not the user name to create).
156
157 -w
158 --no-password
159 Never issue a password prompt. If the server requires password
160 authentication and a password is not available by other means such
161 as a .pgpass file, the connection attempt will fail. This option
162 can be useful in batch jobs and scripts where no user is present to
163 enter a password.
164
165 -W
166 --password
167 Force createuser to prompt for a password (for connecting to the
168 server, not for the password of the new user).
169
170 This option is never essential, since createuser will automatically
171 prompt for a password if the server demands password
172 authentication. However, createuser will waste a connection attempt
173 finding out that the server wants a password. In some cases it is
174 worth typing -W to avoid the extra connection attempt.
175
177 PGHOST
178 PGPORT
179 PGUSER
180 Default connection parameters
181
182 PG_COLOR
183 Specifies whether to use color in diagnostic messages. Possible
184 values are always, auto and never.
185
186 This utility, like most other PostgreSQL utilities, also uses the
187 environment variables supported by libpq (see Section 34.15).
188
190 In case of difficulty, see CREATE ROLE (CREATE_ROLE(7)) and psql(1) for
191 discussions of potential problems and error messages. The database
192 server must be running at the targeted host. Also, any default
193 connection settings and environment variables used by the libpq
194 front-end library will apply.
195
197 To create a user joe on the default database server:
198
199 $ createuser joe
200
201 To create a user joe on the default database server with prompting for
202 some additional attributes:
203
204 $ createuser --interactive joe
205 Shall the new role be a superuser? (y/n) n
206 Shall the new role be allowed to create databases? (y/n) n
207 Shall the new role be allowed to create more new roles? (y/n) n
208
209 To create the same user joe using the server on host eden, port 5000,
210 with attributes explicitly specified, taking a look at the underlying
211 command:
212
213 $ createuser -h eden -p 5000 -S -D -R -e joe
214 CREATE ROLE joe NOSUPERUSER NOCREATEDB NOCREATEROLE INHERIT LOGIN;
215
216 To create the user joe as a superuser, and assign a password
217 immediately:
218
219 $ createuser -P -s -e joe
220 Enter password for new role: xyzzy
221 Enter it again: xyzzy
222 CREATE ROLE joe PASSWORD 'md5b5f5ba1a423792b526f799ae4eb3d59e' SUPERUSER CREATEDB CREATEROLE INHERIT LOGIN;
223
224 In the above example, the new password isn't actually echoed when
225 typed, but we show what was typed for clarity. As you see, the password
226 is encrypted before it is sent to the client.
227
229 dropuser(1), CREATE ROLE (CREATE_ROLE(7))
230
231
232
233PostgreSQL 15.4 2023 CREATEUSER(1)