2
$PostgreSQL: pgsql/doc/src/sgml/ref/create_database.sgml,v 1.43 2004-10-29 03:17:22 neilc 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
The name of the tablespace that will be associated with the
117
new database, or <literal>DEFAULT</literal> to use the
118
template database's tablespace. This
119
tablespace will be the default tablespace used for objects
120
created in this database. See
121
<xref linkend="sql-createtablespace" endterm="sql-createtablespace-title">
122
for more information.
129
Optional parameters can be written in any order, not only the order
138
<command>CREATE DATABASE</> cannot be executed inside a transaction
143
Errors along the line of <quote>could not initialize database directory</>
144
are most likely related to insufficient permissions on the data
145
directory, a full disk, or other file system problems.
149
Use <xref linkend="SQL-DROPDATABASE" endterm="SQL-DROPDATABASE-title"> to remove a database.
153
The program <xref linkend="APP-CREATEDB" endterm="APP-CREATEDB-title"> is a
154
wrapper program around this command, provided for convenience.
158
Although it is possible to copy a database other than <literal>template1</>
159
by specifying its name as the template, this is not (yet) intended as
160
a general-purpose <quote><command>COPY DATABASE</command></quote> facility.
161
We recommend that databases used as templates be treated as read-only.
162
See <xref linkend="manage-ag-templatedbs"> for more information.
167
<title>Examples</title>
170
To create a new database:
173
CREATE DATABASE lusiadas;
178
To create a database <literal>sales</> owned by user <literal>salesapp</>
179
with a default tablespace of <literal>salesspace</>:
182
CREATE DATABASE sales OWNER salesapp TABLESPACE salesspace;
187
To create a database <literal>music</> which supports the ISO-8859-1
191
CREATE DATABASE music ENCODING 'LATIN1';
197
<title>Compatibility</title>
200
There is no <command>CREATE DATABASE</command> statement in the SQL
201
standard. Databases are equivalent to catalogs, whose creation is
202
implementation-defined.
207
<!-- Keep this comment at the end of the file
212
sgml-minimize-attributes:nil
213
sgml-always-quote-attributes:t
216
sgml-parent-document:nil
217
sgml-default-dtd-file:"../reference.ced"
218
sgml-exposed-tags:nil
219
sgml-local-catalogs:"/usr/lib/sgml/catalog"
220
sgml-local-ecat-files:nil