3
PostgreSQL documentation
6
<refentry id="APP-CREATEDB">
8
<refentrytitle id="APP-CREATEDB-TITLE"><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>option</replaceable></arg>
26
<arg><replaceable>dbname</replaceable></arg>
27
<arg><replaceable>description</replaceable></arg>
32
<refsect1 id="R1-APP-CREATEDB-1">
37
<application>createdb</application> creates a new <productname>PostgreSQL</productname>
42
Normally, the database user who executes this command becomes the owner of
44
However a different owner can be specified via the <option>-O</option>
45
option, if the executing user has appropriate privileges.
49
<application>createdb</application> is a wrapper around the
50
<acronym>SQL</acronym> command <xref linkend="SQL-CREATEDATABASE"
51
endterm="SQL-CREATEDATABASE-title">.
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>-l <replaceable class="parameter">locale</replaceable></></term>
111
<term><option>--locale <replaceable class="parameter">locale</replaceable></></term>
114
Specifies the locale to be used in this database. This is equivalent
115
to specifying both <option>--lc-collate</option> and <option>--lc-ctype</option>.
121
<term><option>--lc-collate <replaceable class="parameter">locale</replaceable></></term>
124
Specifies the LC_COLLATE setting to be used in this database.
130
<term><option>--lc-ctype <replaceable class="parameter">locale</replaceable></></term>
133
Specifies the LC_CTYPE setting to be used in this database.
139
<term><option>-E <replaceable class="parameter">encoding</replaceable></></term>
140
<term><option>--encoding <replaceable class="parameter">encoding</replaceable></></term>
143
Specifies the character encoding scheme to be used in this
144
database. The character sets supported by the
145
<productname>PostgreSQL</productname> server are described in
146
<xref linkend="multibyte-charset-supported">.
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.
174
The options <option>-D</option>, <option>-E</option>, <option>-l</option>,
175
<option>-O</option>, and
176
<option>-T</option> correspond to options of the underlying
177
SQL command <xref linkend="SQL-CREATEDATABASE"
178
endterm="SQL-CREATEDATABASE-title">; see there for more information
183
<application>createdb</application> also accepts the following
184
command-line arguments for connection parameters:
188
<term><option>-h <replaceable class="parameter">host</replaceable></></term>
189
<term><option>--host <replaceable class="parameter">host</replaceable></></term>
192
Specifies the host name of the machine on which the
193
server is running. If the value begins with a slash, it is used
194
as the directory for the Unix domain socket.
200
<term><option>-p <replaceable class="parameter">port</replaceable></></term>
201
<term><option>--port <replaceable class="parameter">port</replaceable></></term>
204
Specifies the TCP port or the local Unix domain socket file
205
extension on which the server is listening for connections.
211
<term><option>-U <replaceable class="parameter">username</replaceable></></term>
212
<term><option>--username <replaceable class="parameter">username</replaceable></></term>
215
User name to connect as.
221
<term><option>-w</></term>
222
<term><option>--no-password</></term>
225
Never issue a password prompt. If the server requires
226
password authentication and a password is not available by
227
other means such as a <filename>.pgpass</filename> file, the
228
connection attempt will fail. This option can be useful in
229
batch jobs and scripts where no user is present to enter a
236
<term><option>-W</></term>
237
<term><option>--password</></term>
240
Force <application>createdb</application> to prompt for a
241
password before connecting to a database.
245
This option is never essential, since
246
<application>createdb</application> will automatically prompt
247
for a password if the server demands password authentication.
248
However, <application>createdb</application> will waste a
249
connection attempt finding out that the server wants a password.
250
In some cases it is worth typing <option>-W</> to avoid the extra
262
<title>Environment</title>
266
<term><envar>PGDATABASE</envar></term>
269
If set, the name of the database to create, unless overridden on
276
<term><envar>PGHOST</envar></term>
277
<term><envar>PGPORT</envar></term>
278
<term><envar>PGUSER</envar></term>
282
Default connection parameters. <envar>PGUSER</envar> also
283
determines the name of the database to create, if it is not
284
specified on the command line or by <envar>PGDATABASE</envar>.
291
This utility, like most other <productname>PostgreSQL</> utilities,
292
also uses the environment variables supported by <application>libpq</>
293
(see <xref linkend="libpq-envars">).
300
<title>Diagnostics</title>
303
In case of difficulty, see <xref linkend="SQL-CREATEDATABASE"
304
endterm="sql-createdatabase-title"> and <xref linkend="APP-PSQL"> for
305
discussions of potential problems and error messages.
306
The database server must be running at the
307
targeted host. Also, any default connection settings and environment
308
variables used by the <application>libpq</application> front-end
316
<title>Examples</title>
319
To create the database <literal>demo</literal> using the default
322
<prompt>$ </prompt><userinput>createdb demo</userinput>
327
To create the database <literal>demo</literal> using the
328
server on host <literal>eden</>, port 5000, using the
329
<literal>LATIN1</literal> encoding scheme with a look at the
332
<prompt>$ </prompt><userinput>createdb -p 5000 -h eden -E LATIN1 -e demo</userinput>
333
<computeroutput>CREATE DATABASE demo ENCODING 'LATIN1';</computeroutput>
340
<title>See Also</title>
342
<simplelist type="inline">
343
<member><xref linkend="app-dropdb"></member>
344
<member><xref linkend="sql-createdatabase" endterm="sql-createdatabase-title"></member>