postgresql/doc/src/sgml/ref/create_database.sgml

232 lines
6.1 KiB
Plaintext
Raw Normal View History

<refentry id="SQL-CREATEDATABASE">
<refmeta>
<refentrytitle>
1998-05-13 07:34:00 +02:00
CREATE DATABASE
</refentrytitle>
<refmiscinfo>SQL - Language Statements</refmiscinfo>
</refmeta>
<refnamediv>
<refname>
1998-05-13 07:34:00 +02:00
CREATE DATABASE
</refname>
<refpurpose>
1998-05-13 07:34:00 +02:00
Creates a new database
</refpurpose>
</refnamediv>
<refsynopsisdiv>
<refsynopsisdivinfo>
<date>1998-04-15</date>
</refsynopsisdivinfo>
<synopsis>
CREATE DATABASE <replaceable class="PARAMETER">name</replaceable> [ WITH LOCATION = '<replaceable class="parameter">dbpath</replaceable>' ]
</synopsis>
<refsect2 id="R2-SQL-CREATEDATABASE-1">
<refsect2info>
<date>1998-04-15</date>
</refsect2info>
<title>
1998-05-13 07:34:00 +02:00
Inputs
</title>
<para>
<variablelist>
<varlistentry>
<term><replaceable class="parameter">name</replaceable></term>
<listitem>
<para>
The name of a database to create.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><replaceable class="parameter">dbpath</replaceable></term>
<listitem>
<para>
An alternate location can be specified as either an
environment variable known to the backend server
(e.g. '<envar>PGDATA2</envar>') or as an absolute path name
(e.g. '<filename>/usr/local/pgsql/data</filename>').
In either case, the location must be pre-configured
by <command>initlocation</command>.
</para>
</listitem>
</varlistentry>
</variablelist>
</para>
</refsect2>
<refsect2 id="R2-SQL-CREATEDATABASE-2">
<refsect2info>
<date>1998-04-15</date>
</refsect2info>
<title>
1998-05-13 07:34:00 +02:00
Outputs
</title>
<para>
<variablelist>
<varlistentry>
<term><computeroutput>
CREATEDB
</computeroutput></term>
<listitem>
<para>
Message returned if the command completes successfully.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><computeroutput>
WARN: createdb: database "<replaceable class="parameter">name</replaceable>" already exists.
</computeroutput></term>
<listitem>
<para>
This occurs if <replaceable class="parameter">database</replaceable> specified already exists.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><computeroutput>
ERROR: Unable to create database directory <replaceable class="parameter">directory</replaceable>
</computeroutput></term>
<listitem>
<para>
There was a problem with creating the required directory; this operation will
need permissions for the <literal>postgres</literal> user on the specified location.
</para>
</listitem>
</varlistentry>
</variablelist>
</para>
</refsect2>
</refsynopsisdiv>
<refsect1 id="R1-SQL-CREATEDATABASE-1">
<refsect1info>
<date>1998-04-15</date>
</refsect1info>
<title>
1998-05-13 07:34:00 +02:00
Description
</title>
<para>
<command>CREATE DATABASE</command> creates a new Postgres database.
1998-05-13 07:34:00 +02:00
The creator becomes the administrator of the new database.
</para>
<refsect2 id="R2-SQL-CREATEDATABASE-3">
<refsect2info>
<date>1998-04-15</date>
</refsect2info>
<title>
1998-05-13 07:34:00 +02:00
Notes
</title>
<para>
1998-09-16 16:43:12 +02:00
<command>CREATE DATABASE</command> is a <productname>Postgres</productname>
language extension.
</para>
1998-05-13 07:34:00 +02:00
<para>
1998-09-16 16:43:12 +02:00
Use <command>DROP DATABASE</command> to remove a database.
1998-05-13 07:34:00 +02:00
</para>
</refsect2>
</refsect1>
<refsect1 id="R1-SQL-CREATEDATABASE-2">
<title>
1998-05-13 07:34:00 +02:00
Usage
</title>
<para>
1998-05-13 07:34:00 +02:00
To create a new database:
<programlisting>
<prompt>olly=></prompt> <userinput>create database lusiadas;</userinput>
</programlisting>
</para>
<para>
To create a new database in an alternate area <filename>~/private_db</filename>:
<programlisting>
<prompt>$</prompt> <userinput>mkdir private_db</userinput>
<prompt>$</prompt> <userinput>initlocation ~/private_db</userinput>
<computeroutput>Creating Postgres database system directory /home/olly/private_db/base</computeroutput>
<prompt>$</prompt> <userinput>psql olly</userinput>
<computeroutput>Welcome to the POSTGRESQL interactive sql monitor:
Please read the file COPYRIGHT for copyright terms of POSTGRESQL
type \? for help on slash commands
type \q to quit
type \g or terminate with semicolon to execute query
You are currently connected to the database: template1
<prompt>olly=></prompt></computeroutput> <userinput>create database elsewhere with location = '/home/olly/private_db';</userinput>
<computeroutput>CREATEDB</computeroutput>
</programlisting>
</para>
</refsect1>
<refsect1 id="R1-SQL-CREATEDATABASE-3">
<title>
1998-05-13 07:34:00 +02:00
Bugs
</title>
<para>
1998-09-16 16:43:12 +02:00
There are security and data integrity issues
involved with using alternate database locations
1998-09-16 16:43:12 +02:00
specified with absolute path names, and by default
only an environment variable known to the backend may be
specified for an alternate location.
See the Administrator's Guide for more information.
</para>
</refsect1>
<!--
comment from Olly; response from Thomas...
1998-05-13 07:34:00 +02:00
<comment>
initlocation does not create a PG_VERSION file in the specified location.
How will Postgres handle the situation if it is upgraded to an
1998-05-13 07:34:00 +02:00
incompatible database version?
</comment>
Hmm. This isn't an issue since the upgrade would do a dump/reload from the main database area also.
Not sure if the dump/reload would guarantee that the alternate data area gets refreshed though...
-->
1998-05-13 07:34:00 +02:00
<refsect1 id="R1-SQL-CREATEDATABASE-4">
<title>
1998-05-13 07:34:00 +02:00
Compatibility
</title>
<refsect2 id="R2-SQL-CREATEDATABASE-4">
<refsect2info>
<date>1998-04-15</date>
</refsect2info>
<title>
1998-05-13 07:34:00 +02:00
SQL92
</title>
<para>
1998-09-16 16:43:12 +02:00
There is no <command>CREATE DATABASE</command> statement in SQL92.
</para>
1998-05-13 07:34:00 +02:00
<para>
The equivalent command in standard SQL is <command>CREATE SCHEMA</command>.
</para>
</refsect2>
</refsect1>
</refentry>
1998-05-13 07:34:00 +02:00
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
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:
-->