2 $PostgreSQL: pgsql/doc/src/sgml/ref/create_database.sgml,v 1.41 2004/07/17 16:33:31 tgl Exp $
3 PostgreSQL documentation
6 <refentry id="SQL-CREATEDATABASE">
8 <refentrytitle id="sql-createdatabase-title">CREATE DATABASE</refentrytitle>
9 <refmiscinfo>SQL - Language Statements</refmiscinfo>
13 <refname>CREATE DATABASE</refname>
14 <refpurpose>create a new database</refpurpose>
17 <indexterm zone="sql-createdatabase">
18 <primary>CREATE DATABASE</primary>
23 CREATE DATABASE <replaceable class="PARAMETER">name</replaceable>
24 [ [ WITH ] [ OWNER [=] <replaceable class="parameter">dbowner</replaceable> ]
25 [ TEMPLATE [=] <replaceable class="parameter">template</replaceable> ]
26 [ ENCODING [=] <replaceable class="parameter">encoding</replaceable> ]
27 [ TABLESPACE [=] <replaceable class="parameter">tablespace</replaceable> ] ]
32 <title>Description</title>
35 <command>CREATE DATABASE</command> creates a new
36 <productname>PostgreSQL</productname> database.
40 To create a database, you must be a superuser or have the special
41 <literal>CREATEDB</> privilege.
42 See <xref linkend="SQL-CREATEUSER" endterm="SQL-CREATEUSER-title">.
46 Normally, the creator becomes the owner of the new database.
47 Superusers can create databases owned by other users using the
48 <literal>OWNER</> clause. They can even create databases owned by
49 users with no special privileges. Non-superusers with <literal>CREATEDB</>
50 privilege can only create databases owned by themselves.
54 By default, the new database will be created by cloning the standard
55 system database <literal>template1</>. A different template can be
56 specified by writing <literal>TEMPLATE
57 <replaceable class="parameter">name</replaceable></literal>. In particular,
58 by writing <literal>TEMPLATE template0</>, you can create a virgin
59 database containing only the standard objects predefined by your
60 version of <productname>PostgreSQL</productname>. This is useful
61 if you wish to avoid copying
62 any installation-local objects that may have been added to
63 <literal>template1</>.
68 <title>Parameters</title>
72 <term><replaceable class="parameter">name</replaceable></term>
75 The name of a database to create.
80 <term><replaceable class="parameter">dbowner</replaceable></term>
83 The name of the database user who will own the new database,
84 or <literal>DEFAULT</literal> to use the default (namely, the
85 user executing the command).
90 <term><replaceable class="parameter">template</replaceable></term>
93 The name of the template from which to create the new database,
94 or <literal>DEFAULT</literal> to use the default template
95 (<literal>template1</literal>).
100 <term><replaceable class="parameter">encoding</replaceable></term>
103 Character set encoding to use in the new database. Specify
104 a string constant (e.g., <literal>'SQL_ASCII'</literal>),
105 or an integer encoding number, or <literal>DEFAULT</literal>
106 to use the default encoding. The character sets supported by the
107 <productname>PostgreSQL</productname> server are described in
108 <xref linkend="multibyte-charset-supported">.
113 <term><replaceable class="parameter">tablespace</replaceable></term>
116 Specifies the default tablespace for the new database.
117 If not specified, the same tablespace that is default for
118 the template database is used. See
119 <xref linkend="sql-createtablespace" endterm="sql-createtablespace-title">
120 for more information.
127 Optional parameters can be written in any order, not only the order
136 <command>CREATE DATABASE</> cannot be executed inside a transaction
141 Errors along the line of <quote>could not initialize database directory</>
142 are most likely related to insufficient permissions on the data
143 directory, a full disk, or other file system problems.
147 Use <xref linkend="SQL-DROPDATABASE" endterm="SQL-DROPDATABASE-title"> to remove a database.
151 The program <xref linkend="APP-CREATEDB" endterm="APP-CREATEDB-title"> is a
152 wrapper program around this command, provided for convenience.
156 Although it is possible to copy a database other than <literal>template1</>
157 by specifying its name as the template, this is not (yet) intended as
158 a general-purpose <quote><command>COPY DATABASE</command></quote> facility.
159 We recommend that databases used as templates be treated as read-only.
160 See <xref linkend="manage-ag-templatedbs"> for more information.
165 <title>Examples</title>
168 To create a new database:
171 CREATE DATABASE lusiadas;
176 To create a database <literal>sales</> owned by user <literal>salesapp</>>
177 with a default tablespace of <literal>salesspace</>:
180 CREATE DATABASE sales OWNER salesapp TABLESPACE salesspace;
185 To create a database <literal>music</> which supports the ISO-8859-1
189 CREATE DATABASE music ENCODING 'LATIN1';
195 <title>Compatibility</title>
198 There is no <command>CREATE DATABASE</command> statement in the SQL
199 standard. Databases are equivalent to catalogs, whose creation is
200 implementation-defined.
205 <!-- Keep this comment at the end of the file
210 sgml-minimize-attributes:nil
211 sgml-always-quote-attributes:t
214 sgml-parent-document:nil
215 sgml-default-dtd-file:"../reference.ced"
216 sgml-exposed-tags:nil
217 sgml-local-catalogs:"/usr/lib/sgml/catalog"
218 sgml-local-ecat-files:nil