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.
99 <term><option>-e</></term>
100 <term><option>--echo</></term>
103 Echo the commands that <application>createdb</application> generates
104 and sends to the server.
110 <term><option>-E <replaceable class="parameter">encoding</replaceable></></term>
111 <term><option>--encoding=<replaceable class="parameter">encoding</replaceable></></term>
114 Specifies the character encoding scheme to be used in this
115 database. The character sets supported by the
116 <productname>PostgreSQL</productname> server are described in
117 <xref linkend="multibyte-charset-supported">.
123 <term><option>-l <replaceable class="parameter">locale</replaceable></></term>
124 <term><option>--locale=<replaceable class="parameter">locale</replaceable></></term>
127 Specifies the locale to be used in this database. This is equivalent
128 to specifying both <option>--lc-collate</option> and <option>--lc-ctype</option>.
134 <term><option>--lc-collate=<replaceable class="parameter">locale</replaceable></></term>
137 Specifies the LC_COLLATE setting to be used in this database.
143 <term><option>--lc-ctype=<replaceable class="parameter">locale</replaceable></></term>
146 Specifies the LC_CTYPE setting to be used in this database.
152 <term><option>-O <replaceable class="parameter">owner</replaceable></></term>
153 <term><option>--owner=<replaceable class="parameter">owner</replaceable></></term>
156 Specifies the database user who will own the new database.
162 <term><option>-T <replaceable class="parameter">template</replaceable></></term>
163 <term><option>--template=<replaceable class="parameter">template</replaceable></></term>
166 Specifies the template database from which to build this database.
172 <term><option>-V</></term>
173 <term><option>--version</></term>
176 Print the <application>createdb</application> version and exit.
182 <term><option>-?</></term>
183 <term><option>--help</></term>
186 Show help about <application>createdb</application> command line
196 The options <option>-D</option>, <option>-l</option>, <option>-E</option>,
197 <option>-O</option>, and
198 <option>-T</option> correspond to options of the underlying
199 SQL command <xref linkend="SQL-CREATEDATABASE">; see there for more information
204 <application>createdb</application> also accepts the following
205 command-line arguments for connection parameters:
209 <term><option>-h <replaceable class="parameter">host</replaceable></></term>
210 <term><option>--host=<replaceable class="parameter">host</replaceable></></term>
213 Specifies the host name of the machine on which the
214 server is running. If the value begins with a slash, it is used
215 as the directory for the Unix domain socket.
221 <term><option>-p <replaceable class="parameter">port</replaceable></></term>
222 <term><option>--port=<replaceable class="parameter">port</replaceable></></term>
225 Specifies the TCP port or the local Unix domain socket file
226 extension on which the server is listening for connections.
232 <term><option>-U <replaceable class="parameter">username</replaceable></></term>
233 <term><option>--username=<replaceable class="parameter">username</replaceable></></term>
236 User name to connect as.
242 <term><option>-w</></term>
243 <term><option>--no-password</></term>
246 Never issue a password prompt. If the server requires
247 password authentication and a password is not available by
248 other means such as a <filename>.pgpass</filename> file, the
249 connection attempt will fail. This option can be useful in
250 batch jobs and scripts where no user is present to enter a
257 <term><option>-W</></term>
258 <term><option>--password</></term>
261 Force <application>createdb</application> to prompt for a
262 password before connecting to a database.
266 This option is never essential, since
267 <application>createdb</application> will automatically prompt
268 for a password if the server demands password authentication.
269 However, <application>createdb</application> will waste a
270 connection attempt finding out that the server wants a password.
271 In some cases it is worth typing <option>-W</> to avoid the extra
283 <title>Environment</title>
287 <term><envar>PGDATABASE</envar></term>
290 If set, the name of the database to create, unless overridden on
297 <term><envar>PGHOST</envar></term>
298 <term><envar>PGPORT</envar></term>
299 <term><envar>PGUSER</envar></term>
303 Default connection parameters. <envar>PGUSER</envar> also
304 determines the name of the database to create, if it is not
305 specified on the command line or by <envar>PGDATABASE</envar>.
312 This utility, like most other <productname>PostgreSQL</> utilities,
313 also uses the environment variables supported by <application>libpq</>
314 (see <xref linkend="libpq-envars">).
321 <title>Diagnostics</title>
324 In case of difficulty, see <xref linkend="SQL-CREATEDATABASE">
325 and <xref linkend="APP-PSQL"> for
326 discussions of potential problems and error messages.
327 The database server must be running at the
328 targeted host. Also, any default connection settings and environment
329 variables used by the <application>libpq</application> front-end
337 <title>Examples</title>
340 To create the database <literal>demo</literal> using the default
343 <prompt>$ </prompt><userinput>createdb demo</userinput>
348 To create the database <literal>demo</literal> using the
349 server on host <literal>eden</>, port 5000, using the
350 <literal>LATIN1</literal> encoding scheme with a look at the
353 <prompt>$ </prompt><userinput>createdb -p 5000 -h eden -E LATIN1 -e demo</userinput>
354 <computeroutput>CREATE DATABASE demo ENCODING 'LATIN1';</computeroutput>
360 <title>See Also</title>
362 <simplelist type="inline">
363 <member><xref linkend="app-dropdb"></member>
364 <member><xref linkend="sql-createdatabase"></member>