2 $PostgreSQL: pgsql/doc/src/sgml/ref/createdb.sgml,v 1.46 2007/06/21 10:43:09 petere Exp $
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>-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>-O <replaceable class="parameter">owner</replaceable></></term>
124 <term><option>--owner <replaceable class="parameter">owner</replaceable></></term>
127 Specifies the database user who will own the new database.
133 <term><option>-T <replaceable class="parameter">template</replaceable></></term>
134 <term><option>--template <replaceable class="parameter">template</replaceable></></term>
137 Specifies the template database from which to build this database.
145 The options <option>-D</option>, <option>-E</option>,
146 <option>-O</option>, and
147 <option>-T</option> correspond to options of the underlying
148 SQL command <xref linkend="SQL-CREATEDATABASE"
149 endterm="SQL-CREATEDATABASE-title">; see there for more information
154 <application>createdb</application> also accepts the following
155 command-line arguments for connection parameters:
159 <term><option>-h <replaceable class="parameter">host</replaceable></></term>
160 <term><option>--host <replaceable class="parameter">host</replaceable></></term>
163 Specifies the host name of the machine on which the
164 server is running. If the value begins with a slash, it is used
165 as the directory for the Unix domain socket.
171 <term><option>-p <replaceable class="parameter">port</replaceable></></term>
172 <term><option>--port <replaceable class="parameter">port</replaceable></></term>
175 Specifies the TCP port or the local Unix domain socket file
176 extension on which the server is listening for connections.
182 <term><option>-U <replaceable class="parameter">username</replaceable></></term>
183 <term><option>--username <replaceable class="parameter">username</replaceable></></term>
186 User name to connect as
192 <term><option>-W</></term>
193 <term><option>--password</></term>
196 Force password prompt.
207 <title>Environment</title>
211 <term><envar>PGDATABASE</envar></term>
214 If set, the name of the database to create, unless overridden on
221 <term><envar>PGHOST</envar></term>
222 <term><envar>PGPORT</envar></term>
223 <term><envar>PGUSER</envar></term>
227 Default connection parameters. <envar>PGUSER</envar> also
228 determines the name of the database to create, if it is not
229 specified on the command line or by <envar>PGDATABASE</envar>.
236 This utility, like most other <productname>PostgreSQL</> utilities,
237 also uses the environment variables supported by <application>libpq</>
238 (see <xref linkend="libpq-envars">).
245 <title>Diagnostics</title>
248 In case of difficulty, see <xref linkend="SQL-CREATEDATABASE"
249 endterm="sql-createdatabase-title"> and <xref linkend="APP-PSQL"> for
250 discussions of potential problems and error messages.
251 The database server must be running at the
252 targeted host. Also, any default connection settings and environment
253 variables used by the <application>libpq</application> front-end
261 <title>Examples</title>
264 To create the database <literal>demo</literal> using the default
267 <prompt>$ </prompt><userinput>createdb demo</userinput>
272 To create the database <literal>demo</literal> using the
273 server on host <literal>eden</>, port 5000, using the
274 <literal>LATIN1</literal> encoding scheme with a look at the
277 <prompt>$ </prompt><userinput>createdb -p 5000 -h eden -E LATIN1 -e demo</userinput>
278 <computeroutput>CREATE DATABASE demo ENCODING 'LATIN1';</computeroutput>
285 <title>See Also</title>
287 <simplelist type="inline">
288 <member><xref linkend="app-dropdb"></member>
289 <member><xref linkend="sql-createdatabase" endterm="sql-createdatabase-title"></member>