1999-07-22 17:09:15 +02:00
|
|
|
<!--
|
2004-07-17 18:33:31 +02:00
|
|
|
$PostgreSQL: pgsql/doc/src/sgml/ref/create_database.sgml,v 1.41 2004/07/17 16:33:31 tgl Exp $
|
2001-12-08 04:24:40 +01:00
|
|
|
PostgreSQL documentation
|
1999-07-22 17:09:15 +02:00
|
|
|
-->
|
|
|
|
|
1999-07-06 19:16:42 +02:00
|
|
|
<refentry id="SQL-CREATEDATABASE">
|
|
|
|
<refmeta>
|
2002-04-21 21:02:39 +02:00
|
|
|
<refentrytitle id="sql-createdatabase-title">CREATE DATABASE</refentrytitle>
|
1999-07-06 19:16:42 +02:00
|
|
|
<refmiscinfo>SQL - Language Statements</refmiscinfo>
|
|
|
|
</refmeta>
|
2003-04-22 12:08:08 +02:00
|
|
|
|
1999-07-06 19:16:42 +02:00
|
|
|
<refnamediv>
|
2003-04-22 12:08:08 +02:00
|
|
|
<refname>CREATE DATABASE</refname>
|
|
|
|
<refpurpose>create a new database</refpurpose>
|
1998-12-29 03:24:47 +01:00
|
|
|
</refnamediv>
|
2003-04-22 12:08:08 +02:00
|
|
|
|
2003-08-31 19:32:24 +02:00
|
|
|
<indexterm zone="sql-createdatabase">
|
|
|
|
<primary>CREATE DATABASE</primary>
|
|
|
|
</indexterm>
|
|
|
|
|
1999-07-06 19:16:42 +02:00
|
|
|
<refsynopsisdiv>
|
2003-04-22 12:08:08 +02:00
|
|
|
<synopsis>
|
2000-11-14 19:37:49 +01:00
|
|
|
CREATE DATABASE <replaceable class="PARAMETER">name</replaceable>
|
2002-06-17 07:40:32 +02:00
|
|
|
[ [ WITH ] [ OWNER [=] <replaceable class="parameter">dbowner</replaceable> ]
|
2002-02-25 04:37:14 +01:00
|
|
|
[ TEMPLATE [=] <replaceable class="parameter">template</replaceable> ]
|
2004-06-18 08:14:31 +02:00
|
|
|
[ ENCODING [=] <replaceable class="parameter">encoding</replaceable> ]
|
|
|
|
[ TABLESPACE [=] <replaceable class="parameter">tablespace</replaceable> ] ]
|
2003-04-22 12:08:08 +02:00
|
|
|
</synopsis>
|
|
|
|
</refsynopsisdiv>
|
|
|
|
|
|
|
|
<refsect1>
|
|
|
|
<title>Description</title>
|
|
|
|
|
|
|
|
<para>
|
|
|
|
<command>CREATE DATABASE</command> creates a new
|
|
|
|
<productname>PostgreSQL</productname> database.
|
|
|
|
</para>
|
|
|
|
|
2003-09-12 02:12:47 +02:00
|
|
|
<para>
|
|
|
|
To create a database, you must be a superuser or have the special
|
|
|
|
<literal>CREATEDB</> privilege.
|
|
|
|
See <xref linkend="SQL-CREATEUSER" endterm="SQL-CREATEUSER-title">.
|
|
|
|
</para>
|
|
|
|
|
2003-04-22 12:08:08 +02:00
|
|
|
<para>
|
|
|
|
Normally, the creator becomes the owner of the new database.
|
|
|
|
Superusers can create databases owned by other users using the
|
|
|
|
<literal>OWNER</> clause. They can even create databases owned by
|
|
|
|
users with no special privileges. Non-superusers with <literal>CREATEDB</>
|
|
|
|
privilege can only create databases owned by themselves.
|
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
|
|
|
By default, the new database will be created by cloning the standard
|
|
|
|
system database <literal>template1</>. A different template can be
|
|
|
|
specified by writing <literal>TEMPLATE
|
|
|
|
<replaceable class="parameter">name</replaceable></literal>. In particular,
|
|
|
|
by writing <literal>TEMPLATE template0</>, you can create a virgin
|
|
|
|
database containing only the standard objects predefined by your
|
|
|
|
version of <productname>PostgreSQL</productname>. This is useful
|
|
|
|
if you wish to avoid copying
|
|
|
|
any installation-local objects that may have been added to
|
2004-06-18 08:14:31 +02:00
|
|
|
<literal>template1</>.
|
2003-04-22 12:08:08 +02:00
|
|
|
</para>
|
|
|
|
</refsect1>
|
|
|
|
|
|
|
|
<refsect1>
|
2003-09-12 02:12:47 +02:00
|
|
|
<title>Parameters</title>
|
1999-07-06 19:16:42 +02:00
|
|
|
|
|
|
|
<variablelist>
|
|
|
|
<varlistentry>
|
|
|
|
<term><replaceable class="parameter">name</replaceable></term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
2004-06-18 08:14:31 +02:00
|
|
|
The name of a database to create.
|
1999-07-06 19:16:42 +02:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
2002-02-24 21:20:21 +01:00
|
|
|
<varlistentry>
|
|
|
|
<term><replaceable class="parameter">dbowner</replaceable></term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
2003-04-22 12:08:08 +02:00
|
|
|
The name of the database user who will own the new database,
|
2004-06-18 08:14:31 +02:00
|
|
|
or <literal>DEFAULT</literal> to use the default (namely, the
|
|
|
|
user executing the command).
|
2002-02-24 21:20:21 +01:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
1999-07-06 19:16:42 +02:00
|
|
|
<varlistentry>
|
2004-06-18 08:14:31 +02:00
|
|
|
<term><replaceable class="parameter">template</replaceable></term>
|
1999-07-06 19:16:42 +02:00
|
|
|
<listitem>
|
|
|
|
<para>
|
2004-06-18 08:14:31 +02:00
|
|
|
The name of the template from which to create the new database,
|
|
|
|
or <literal>DEFAULT</literal> to use the default template
|
|
|
|
(<literal>template1</literal>).
|
2000-11-14 19:37:49 +01:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
<varlistentry>
|
2004-06-18 08:14:31 +02:00
|
|
|
<term><replaceable class="parameter">encoding</replaceable></term>
|
2000-11-14 19:37:49 +01:00
|
|
|
<listitem>
|
|
|
|
<para>
|
2004-06-18 08:14:31 +02:00
|
|
|
Character set encoding to use in the new database. Specify
|
|
|
|
a string constant (e.g., <literal>'SQL_ASCII'</literal>),
|
|
|
|
or an integer encoding number, or <literal>DEFAULT</literal>
|
|
|
|
to use the default encoding. The character sets supported by the
|
|
|
|
<productname>PostgreSQL</productname> server are described in
|
|
|
|
<xref linkend="multibyte-charset-supported">.
|
2000-11-14 19:37:49 +01:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
<varlistentry>
|
2004-06-18 08:14:31 +02:00
|
|
|
<term><replaceable class="parameter">tablespace</replaceable></term>
|
2000-11-14 19:37:49 +01:00
|
|
|
<listitem>
|
|
|
|
<para>
|
2004-06-18 08:14:31 +02:00
|
|
|
Specifies the default tablespace for the new database.
|
|
|
|
If not specified, the same tablespace that is default for
|
|
|
|
the template database is used. See
|
|
|
|
<xref linkend="sql-createtablespace" endterm="sql-createtablespace-title">
|
|
|
|
for more information.
|
1999-07-06 19:16:42 +02:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
</variablelist>
|
2003-04-22 12:08:08 +02:00
|
|
|
|
|
|
|
<para>
|
|
|
|
Optional parameters can be written in any order, not only the order
|
|
|
|
illustrated above.
|
|
|
|
</para>
|
|
|
|
</refsect1>
|
|
|
|
|
|
|
|
<refsect1>
|
2003-09-12 02:12:47 +02:00
|
|
|
<title>Notes</title>
|
1999-12-12 06:15:10 +01:00
|
|
|
|
2003-09-12 02:12:47 +02:00
|
|
|
<para>
|
|
|
|
<command>CREATE DATABASE</> cannot be executed inside a transaction
|
|
|
|
block.
|
|
|
|
</para>
|
2000-11-14 19:37:49 +01:00
|
|
|
|
2003-09-12 02:12:47 +02:00
|
|
|
<para>
|
|
|
|
Errors along the line of <quote>could not initialize database directory</>
|
|
|
|
are most likely related to insufficient permissions on the data
|
2004-06-18 08:14:31 +02:00
|
|
|
directory, a full disk, or other file system problems.
|
2003-09-12 02:12:47 +02:00
|
|
|
</para>
|
2000-11-14 19:37:49 +01:00
|
|
|
|
1998-05-13 07:34:00 +02:00
|
|
|
<para>
|
1999-12-12 06:15:10 +01:00
|
|
|
Use <xref linkend="SQL-DROPDATABASE" endterm="SQL-DROPDATABASE-title"> to remove a database.
|
|
|
|
</para>
|
1999-07-22 17:09:15 +02:00
|
|
|
|
|
|
|
<para>
|
2003-04-22 12:08:08 +02:00
|
|
|
The program <xref linkend="APP-CREATEDB" endterm="APP-CREATEDB-title"> is a
|
|
|
|
wrapper program around this command, provided for convenience.
|
1999-07-22 17:09:15 +02:00
|
|
|
</para>
|
|
|
|
|
2000-11-14 19:37:49 +01:00
|
|
|
<para>
|
2001-11-18 01:38:00 +01:00
|
|
|
Although it is possible to copy a database other than <literal>template1</>
|
|
|
|
by specifying its name as the template, this is not (yet) intended as
|
2003-04-22 12:08:08 +02:00
|
|
|
a general-purpose <quote><command>COPY DATABASE</command></quote> facility.
|
2001-11-18 01:38:00 +01:00
|
|
|
We recommend that databases used as templates be treated as read-only.
|
2003-04-22 12:08:08 +02:00
|
|
|
See <xref linkend="manage-ag-templatedbs"> for more information.
|
2001-08-26 18:56:03 +02:00
|
|
|
</para>
|
1998-12-29 03:24:47 +01:00
|
|
|
</refsect1>
|
1999-07-06 19:16:42 +02:00
|
|
|
|
2003-04-22 12:08:08 +02:00
|
|
|
<refsect1>
|
|
|
|
<title>Examples</title>
|
|
|
|
|
1999-07-06 19:16:42 +02:00
|
|
|
<para>
|
1998-05-13 07:34:00 +02:00
|
|
|
To create a new database:
|
1999-07-06 19:16:42 +02:00
|
|
|
|
2003-04-22 12:08:08 +02:00
|
|
|
<programlisting>
|
|
|
|
CREATE DATABASE lusiadas;
|
2004-07-12 03:22:53 +02:00
|
|
|
</programlisting>
|
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
|
|
|
To create a database <literal>sales</> owned by user <literal>salesapp</>>
|
|
|
|
with a default tablespace of <literal>salesspace</>:
|
|
|
|
|
|
|
|
<programlisting>
|
|
|
|
CREATE DATABASE sales OWNER salesapp TABLESPACE salesspace;
|
|
|
|
</programlisting>
|
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
|
|
|
To create a database <literal>music</> which supports the ISO-8859-1
|
|
|
|
character set:
|
|
|
|
|
|
|
|
<programlisting>
|
|
|
|
CREATE DATABASE music ENCODING 'LATIN1';
|
2003-04-22 12:08:08 +02:00
|
|
|
</programlisting>
|
1999-07-06 19:16:42 +02:00
|
|
|
</para>
|
|
|
|
</refsect1>
|
|
|
|
|
2003-04-22 12:08:08 +02:00
|
|
|
<refsect1>
|
|
|
|
<title>Compatibility</title>
|
|
|
|
|
|
|
|
<para>
|
|
|
|
There is no <command>CREATE DATABASE</command> statement in the SQL
|
|
|
|
standard. Databases are equivalent to catalogs, whose creation is
|
|
|
|
implementation-defined.
|
|
|
|
</para>
|
1998-05-13 07:34:00 +02:00
|
|
|
</refsect1>
|
1999-07-06 19:16:42 +02:00
|
|
|
</refentry>
|
1998-05-13 07:34:00 +02:00
|
|
|
|
|
|
|
<!-- Keep this comment at the end of the file
|
|
|
|
Local variables:
|
|
|
|
mode: sgml
|
1999-07-06 19:16:42 +02:00
|
|
|
sgml-omittag:nil
|
1998-05-13 07:34:00 +02:00
|
|
|
sgml-shorttag:t
|
|
|
|
sgml-minimize-attributes:nil
|
|
|
|
sgml-always-quote-attributes:t
|
|
|
|
sgml-indent-step:1
|
|
|
|
sgml-indent-data:t
|
|
|
|
sgml-parent-document:nil
|
|
|
|
sgml-default-dtd-file:"../reference.ced"
|
|
|
|
sgml-exposed-tags:nil
|
|
|
|
sgml-local-catalogs:"/usr/lib/sgml/catalog"
|
|
|
|
sgml-local-ecat-files:nil
|
|
|
|
End:
|
|
|
|
-->
|