2 $PostgreSQL: pgsql/doc/src/sgml/ref/create_database.sgml,v 1.44 2005/07/31 17:19:17 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> ]
28 [ CONNECTION LIMIT [=] <replaceable class="parameter">connlimit</replaceable> ] ]
33 <title>Description</title>
36 <command>CREATE DATABASE</command> creates a new
37 <productname>PostgreSQL</productname> database.
41 To create a database, you must be a superuser or have the special
42 <literal>CREATEDB</> privilege.
43 See <xref linkend="SQL-CREATEUSER" endterm="SQL-CREATEUSER-title">.
47 Normally, the creator becomes the owner of the new database.
48 Superusers can create databases owned by other users using the
49 <literal>OWNER</> clause. They can even create databases owned by
50 users with no special privileges. Non-superusers with <literal>CREATEDB</>
51 privilege can only create databases owned by themselves.
55 By default, the new database will be created by cloning the standard
56 system database <literal>template1</>. A different template can be
57 specified by writing <literal>TEMPLATE
58 <replaceable class="parameter">name</replaceable></literal>. In particular,
59 by writing <literal>TEMPLATE template0</>, you can create a virgin
60 database containing only the standard objects predefined by your
61 version of <productname>PostgreSQL</productname>. This is useful
62 if you wish to avoid copying
63 any installation-local objects that may have been added to
64 <literal>template1</>.
69 <title>Parameters</title>
73 <term><replaceable class="parameter">name</replaceable></term>
76 The name of a database to create.
81 <term><replaceable class="parameter">dbowner</replaceable></term>
84 The name of the database user who will own the new database,
85 or <literal>DEFAULT</literal> to use the default (namely, the
86 user executing the command).
91 <term><replaceable class="parameter">template</replaceable></term>
94 The name of the template from which to create the new database,
95 or <literal>DEFAULT</literal> to use the default template
96 (<literal>template1</literal>).
101 <term><replaceable class="parameter">encoding</replaceable></term>
104 Character set encoding to use in the new database. Specify
105 a string constant (e.g., <literal>'SQL_ASCII'</literal>),
106 or an integer encoding number, or <literal>DEFAULT</literal>
107 to use the default encoding. The character sets supported by the
108 <productname>PostgreSQL</productname> server are described in
109 <xref linkend="multibyte-charset-supported">.
114 <term><replaceable class="parameter">tablespace</replaceable></term>
117 The name of the tablespace that will be associated with the
118 new database, or <literal>DEFAULT</literal> to use the
119 template database's tablespace. This
120 tablespace will be the default tablespace used for objects
121 created in this database. See
122 <xref linkend="sql-createtablespace" endterm="sql-createtablespace-title">
123 for more information.
129 <term><replaceable class="parameter">connlimit</replaceable></term>
132 How many concurrent connections can be made
133 to this database. -1 (the default) means no limit.
140 Optional parameters can be written in any order, not only the order
149 <command>CREATE DATABASE</> cannot be executed inside a transaction
154 Errors along the line of <quote>could not initialize database directory</>
155 are most likely related to insufficient permissions on the data
156 directory, a full disk, or other file system problems.
160 Use <xref linkend="SQL-DROPDATABASE" endterm="SQL-DROPDATABASE-title"> to remove a database.
164 The program <xref linkend="APP-CREATEDB" endterm="APP-CREATEDB-title"> is a
165 wrapper program around this command, provided for convenience.
169 Although it is possible to copy a database other than <literal>template1</>
170 by specifying its name as the template, this is not (yet) intended as
171 a general-purpose <quote><command>COPY DATABASE</command></quote> facility.
172 We recommend that databases used as templates be treated as read-only.
173 See <xref linkend="manage-ag-templatedbs"> for more information.
177 The <literal>CONNECTION LIMIT</> option is only enforced approximately;
178 if two new sessions start at about the same time when just one
179 connection <quote>slot</> remains for the database, it is possible that
180 both will fail. Also, the limit is not enforced against superusers.
185 <title>Examples</title>
188 To create a new database:
191 CREATE DATABASE lusiadas;
196 To create a database <literal>sales</> owned by user <literal>salesapp</>
197 with a default tablespace of <literal>salesspace</>:
200 CREATE DATABASE sales OWNER salesapp TABLESPACE salesspace;
205 To create a database <literal>music</> which supports the ISO-8859-1
209 CREATE DATABASE music ENCODING 'LATIN1';
215 <title>Compatibility</title>
218 There is no <command>CREATE DATABASE</command> statement in the SQL
219 standard. Databases are equivalent to catalogs, whose creation is
220 implementation-defined.
225 <!-- Keep this comment at the end of the file
230 sgml-minimize-attributes:nil
231 sgml-always-quote-attributes:t
234 sgml-parent-document:nil
235 sgml-default-dtd-file:"../reference.ced"
236 sgml-exposed-tags:nil
237 sgml-local-catalogs:"/usr/lib/sgml/catalog"
238 sgml-local-ecat-files:nil