2 doc/src/sgml/ref/createdb.sgml
3 PostgreSQL documentation
6 <refentry id="APP-CREATEDB">
8 <refentrytitle><application>createdb</application></refentrytitle>
9 <manvolnum>1</manvolnum>
10 <refmiscinfo>Application</refmiscinfo>
14 <refname>createdb</refname>
15 <refpurpose>create a new <productname>PostgreSQL</productname> database</refpurpose>
18 <indexterm zone="app-createdb">
19 <primary>createdb</primary>
24 <command>createdb</command>
25 <arg rep="repeat"><replaceable>connection-option</replaceable></arg>
26 <arg rep="repeat"><replaceable>option</replaceable></arg>
27 <arg><replaceable>dbname</replaceable></arg>
28 <arg><replaceable>description</replaceable></arg>
33 <refsect1 id="R1-APP-CREATEDB-1">
38 <application>createdb</application> creates a new <productname>PostgreSQL</productname>
43 Normally, the database user who executes this command becomes the owner of
45 However, a different owner can be specified via the <option>-O</option>
46 option, if the executing user has appropriate privileges.
50 <application>createdb</application> is a wrapper around the
51 <acronym>SQL</acronym> command <xref linkend="SQL-CREATEDATABASE">.
52 There is no effective difference between creating databases via
53 this utility and via other methods for accessing the server.
60 <title>Options</title>
63 <application>createdb</application> accepts the following command-line arguments:
67 <term><replaceable class="parameter">dbname</replaceable></term>
70 Specifies the name of the database to be created. The name must be
71 unique among all <productname>PostgreSQL</productname> databases in this cluster.
72 The default is to create a database with the same name as the
79 <term><replaceable class="parameter">description</replaceable></term>
82 Specifies a comment to be associated with the newly created
89 <term><option>-D <replaceable class="parameter">tablespace</replaceable></></term>
90 <term><option>--tablespace=<replaceable class="parameter">tablespace</replaceable></></term>
93 Specifies the default tablespace for the database. (This name
94 is processed as a double-quoted identifier.)
100 <term><option>-e</></term>
101 <term><option>--echo</></term>
104 Echo the commands that <application>createdb</application> generates
105 and sends to the server.
111 <term><option>-E <replaceable class="parameter">encoding</replaceable></></term>
112 <term><option>--encoding=<replaceable class="parameter">encoding</replaceable></></term>
115 Specifies the character encoding scheme to be used in this
116 database. The character sets supported by the
117 <productname>PostgreSQL</productname> server are described in
118 <xref linkend="multibyte-charset-supported">.
124 <term><option>-l <replaceable class="parameter">locale</replaceable></></term>
125 <term><option>--locale=<replaceable class="parameter">locale</replaceable></></term>
128 Specifies the locale to be used in this database. This is equivalent
129 to specifying both <option>--lc-collate</option> and <option>--lc-ctype</option>.
135 <term><option>--lc-collate=<replaceable class="parameter">locale</replaceable></></term>
138 Specifies the LC_COLLATE setting to be used in this database.
144 <term><option>--lc-ctype=<replaceable class="parameter">locale</replaceable></></term>
147 Specifies the LC_CTYPE setting to be used in this database.
153 <term><option>-O <replaceable class="parameter">owner</replaceable></></term>
154 <term><option>--owner=<replaceable class="parameter">owner</replaceable></></term>
157 Specifies the database user who will own the new database.
158 (This name is processed as a double-quoted identifier.)
164 <term><option>-T <replaceable class="parameter">template</replaceable></></term>
165 <term><option>--template=<replaceable class="parameter">template</replaceable></></term>
168 Specifies the template database from which to build this
169 database. (This name is processed as a double-quoted identifier.)
175 <term><option>-V</></term>
176 <term><option>--version</></term>
179 Print the <application>createdb</application> version and exit.
185 <term><option>-?</></term>
186 <term><option>--help</></term>
189 Show help about <application>createdb</application> command line
199 The options <option>-D</option>, <option>-l</option>, <option>-E</option>,
200 <option>-O</option>, and
201 <option>-T</option> correspond to options of the underlying
202 SQL command <xref linkend="SQL-CREATEDATABASE">; see there for more information
207 <application>createdb</application> also accepts the following
208 command-line arguments for connection parameters:
212 <term><option>-h <replaceable class="parameter">host</replaceable></></term>
213 <term><option>--host=<replaceable class="parameter">host</replaceable></></term>
216 Specifies the host name of the machine on which the
217 server is running. If the value begins with a slash, it is used
218 as the directory for the Unix domain socket.
224 <term><option>-p <replaceable class="parameter">port</replaceable></></term>
225 <term><option>--port=<replaceable class="parameter">port</replaceable></></term>
228 Specifies the TCP port or the local Unix domain socket file
229 extension on which the server is listening for connections.
235 <term><option>-U <replaceable class="parameter">username</replaceable></></term>
236 <term><option>--username=<replaceable class="parameter">username</replaceable></></term>
239 User name to connect as.
245 <term><option>-w</></term>
246 <term><option>--no-password</></term>
249 Never issue a password prompt. If the server requires
250 password authentication and a password is not available by
251 other means such as a <filename>.pgpass</filename> file, the
252 connection attempt will fail. This option can be useful in
253 batch jobs and scripts where no user is present to enter a
260 <term><option>-W</></term>
261 <term><option>--password</></term>
264 Force <application>createdb</application> to prompt for a
265 password before connecting to a database.
269 This option is never essential, since
270 <application>createdb</application> will automatically prompt
271 for a password if the server demands password authentication.
272 However, <application>createdb</application> will waste a
273 connection attempt finding out that the server wants a password.
274 In some cases it is worth typing <option>-W</> to avoid the extra
281 <term><option>--maintenance-db=<replaceable class="parameter">dbname</replaceable></></term>
284 Specifies the name of the database to connect to when creating the
285 new database. If not specified, the <literal>postgres</literal>
286 database will be used; if that does not exist (or if it is the name
287 of the new database being created), <literal>template1</literal> will
299 <title>Environment</title>
303 <term><envar>PGDATABASE</envar></term>
306 If set, the name of the database to create, unless overridden on
313 <term><envar>PGHOST</envar></term>
314 <term><envar>PGPORT</envar></term>
315 <term><envar>PGUSER</envar></term>
319 Default connection parameters. <envar>PGUSER</envar> also
320 determines the name of the database to create, if it is not
321 specified on the command line or by <envar>PGDATABASE</envar>.
328 This utility, like most other <productname>PostgreSQL</> utilities,
329 also uses the environment variables supported by <application>libpq</>
330 (see <xref linkend="libpq-envars">).
337 <title>Diagnostics</title>
340 In case of difficulty, see <xref linkend="SQL-CREATEDATABASE">
341 and <xref linkend="APP-PSQL"> for
342 discussions of potential problems and error messages.
343 The database server must be running at the
344 targeted host. Also, any default connection settings and environment
345 variables used by the <application>libpq</application> front-end
353 <title>Examples</title>
356 To create the database <literal>demo</literal> using the default
359 <prompt>$ </prompt><userinput>createdb demo</userinput>
364 To create the database <literal>demo</literal> using the
365 server on host <literal>eden</>, port 5000, using the
366 <literal>LATIN1</literal> encoding scheme with a look at the
369 <prompt>$ </prompt><userinput>createdb -p 5000 -h eden -E LATIN1 -e demo</userinput>
370 <computeroutput>CREATE DATABASE demo ENCODING 'LATIN1';</computeroutput>
376 <title>See Also</title>
378 <simplelist type="inline">
379 <member><xref linkend="app-dropdb"></member>
380 <member><xref linkend="sql-createdatabase"></member>