1CREATEUSER(1)           PostgreSQL 9.2.24 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 new superuser, you must connect as a superuser,
18       not merely with CREATEROLE privilege. Being a superuser implies the
19       ability to bypass all access permission checks within the database, so
20       superuserdom should not be granted lightly.
21
22       createuser is a wrapper around the SQL command CREATE ROLE
23       (CREATE_ROLE(7)). There is no effective difference between creating
24       users via this utility and via other methods for accessing the server.
25

OPTIONS

27       createuser accepts the following command-line arguments:
28
29       username
30           Specifies the name of the PostgreSQL user to be created. This name
31           must be different from all existing roles in this PostgreSQL
32           installation.
33
34       -c number, --connection-limit=number
35           Set a maximum number of connections for the new user. The default
36           is to set no limit.
37
38       -d, --createdb
39           The new user will be allowed to create databases.
40
41       -D, --no-createdb
42           The new user will not be allowed to create databases. This is the
43           default.
44
45       -e, --echo
46           Echo the commands that createuser generates and sends to the
47           server.
48
49       -E, --encrypted
50           Encrypts the user's password stored in the database. If not
51           specified, the default password behavior is used.
52
53       -i, --inherit
54           The new role will automatically inherit privileges of roles it is a
55           member of. This is the default.
56
57       -I, --no-inherit
58           The new role will not automatically inherit privileges of roles it
59           is a member of.
60
61       --interactive
62           Prompt for the user name if none is specified on the command line,
63           and also prompt for whichever of the options -d/-D, -r/-R, -s/-S is
64           not specified on the command line. (This was the default behavior
65           up to PostgreSQL 9.1.)
66
67       -l, --login
68           The new user will be allowed to log in (that is, the user name can
69           be used as the initial session user identifier). This is the
70           default.
71
72       -L, --no-login
73           The new user will not be allowed to log in. (A role without login
74           privilege is still useful as a means of managing database
75           permissions.)
76
77       -N, --unencrypted
78           Does not encrypt the user's password stored in the database. If not
79           specified, the default password behavior is used.
80
81       -P, --pwprompt
82           If given, createuser will issue a prompt for the password of the
83           new user. This is not necessary if you do not plan on using
84           password authentication.
85
86       -r, --createrole
87           The new user will be allowed to create new roles (that is, this
88           user will have CREATEROLE privilege).
89
90       -R, --no-createrole
91           The new user will not be allowed to create new roles. This is the
92           default.
93
94       -s, --superuser
95           The new user will be a superuser.
96
97       -S, --no-superuser
98           The new user will not be a superuser. This is the default.
99
100       -V, --version
101           Print the createuser version and exit.
102
103       --replication
104           The new user will have the REPLICATION privilege, which is
105           described more fully in the documentation for CREATE ROLE
106           (CREATE_ROLE(7)).
107
108       --no-replication
109           The new user will not have the REPLICATION privilege, which is
110           described more fully in the documentation for CREATE ROLE
111           (CREATE_ROLE(7)).
112
113       -?, --help
114           Show help about createuser command line arguments, and exit.
115
116       createuser also accepts the following command-line arguments for
117       connection parameters:
118
119       -h host, --host=host
120           Specifies the host name of the machine on which the server is
121           running. If the value begins with a slash, it is used as the
122           directory for the Unix domain socket.
123
124       -p port, --port=port
125           Specifies the TCP port or local Unix domain socket file extension
126           on which the server is listening for connections.
127
128       -U username, --username=username
129           User name to connect as (not the user name to create).
130
131       -w, --no-password
132           Never issue a password prompt. If the server requires password
133           authentication and a password is not available by other means such
134           as a .pgpass file, the connection attempt will fail. This option
135           can be useful in batch jobs and scripts where no user is present to
136           enter a password.
137
138       -W, --password
139           Force createuser to prompt for a password (for connecting to the
140           server, not for the password of the new user).
141
142           This option is never essential, since createuser will automatically
143           prompt for a password if the server demands password
144           authentication. However, createuser will waste a connection attempt
145           finding out that the server wants a password. In some cases it is
146           worth typing -W to avoid the extra connection attempt.
147

ENVIRONMENT

149       PGHOST, PGPORT, PGUSER
150           Default connection parameters
151
152       This utility, like most other PostgreSQL utilities, also uses the
153       environment variables supported by libpq (see Section 31.14,
154       “Environment Variables”, in the documentation).
155

DIAGNOSTICS

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

EXAMPLES

164       To create a user joe on the default database server:
165
166           $ createuser joe
167
168       To create a user joe on the default database server with prompting for
169       some additional attributes:
170
171           $ createuser --interactive joe
172           Shall the new role be a superuser? (y/n) n
173           Shall the new role be allowed to create databases? (y/n) n
174           Shall the new role be allowed to create more new roles? (y/n) n
175
176       To create the same user joe using the server on host eden, port 5000,
177       with attributes explicitly specified, taking a look at the underlying
178       command:
179
180           $ createuser -h eden -p 5000 -S -D -R -e joe
181           CREATE ROLE joe NOSUPERUSER NOCREATEDB NOCREATEROLE INHERIT LOGIN;
182
183       To create the user joe as a superuser, and assign a password
184       immediately:
185
186           $ createuser -P -s -e joe
187           Enter password for new role: xyzzy
188           Enter it again: xyzzy
189           CREATE ROLE joe PASSWORD 'md5b5f5ba1a423792b526f799ae4eb3d59e' SUPERUSER CREATEDB CREATEROLE INHERIT LOGIN;
190
191       In the above example, the new password isn't actually echoed when
192       typed, but we show what was typed for clarity. As you see, the password
193       is encrypted before it is sent to the client. If the option
194       --unencrypted is used, the password will appear in the echoed command
195       (and possibly also in the server log and elsewhere), so you don't want
196       to use -e in that case, if anyone else can see your screen.
197

SEE ALSO

199       dropuser(1), CREATE ROLE (CREATE_ROLE(7))
200
201
202
203PostgreSQL 9.2.24                 2017-11-06                     CREATEUSER(1)
Impressum