]> granicus.if.org Git - postgresql/blob - doc/src/sgml/ref/create_database.sgml
Markup and editing adjustments...
[postgresql] / doc / src / sgml / ref / create_database.sgml
1 <REFENTRY ID="SQL-CREATEDATABASE">
2  <REFMETA>
3   <REFENTRYTITLE>
4    CREATE DATABASE
5   </REFENTRYTITLE>
6   <REFMISCINFO>SQL - Language Statements</REFMISCINFO>
7  </REFMETA>
8  <REFNAMEDIV>
9   <REFNAME>
10    CREATE DATABASE
11   </REFNAME>
12   <REFPURPOSE>
13    Creates a new database
14   </REFPURPOSE>
15  <REFSYNOPSISDIV>
16   <REFSYNOPSISDIVINFO>
17    <DATE>1998-04-15</DATE>
18   </REFSYNOPSISDIVINFO>
19   <SYNOPSIS>
20 CREATE DATABASE <REPLACEABLE CLASS="PARAMETER">name</REPLACEABLE> [ WITH LOCATION = '<replaceable class="parameter">dbpath</replaceable>' ]
21   </SYNOPSIS>
22   
23   <REFSECT2 ID="R2-SQL-CREATEDATABASE-1">
24    <REFSECT2INFO>
25     <DATE>1998-04-15</DATE>
26    </REFSECT2INFO>
27    <TITLE>
28     Inputs
29    </TITLE>
30    <PARA>
31        <VARIABLELIST>
32         <VARLISTENTRY>
33          <TERM>
34           <replaceable class="parameter">name</replaceable>
35          </TERM>
36          <LISTITEM>
37           <PARA>
38            The name of a database to create.
39           </PARA>
40          </LISTITEM>
41         </VARLISTENTRY>
42         <VARLISTENTRY>
43          <TERM>
44           <replaceable class="parameter">dbpath</replaceable>
45          </TERM>
46          <LISTITEM>
47           <PARA>
48            An alternate location can be specified as either an
49            environment variable known to the backend server
50            (e.g. '<envar>PGDATA2</envar>') or as an absolute path name
51            (e.g. '<filename>/usr/local/pgsql/data</filename>').
52            In either case, the location must be pre-configured
53            by <command>initlocation</command>.
54           </PARA>
55          </LISTITEM>
56         </VARLISTENTRY>
57        </VARIABLELIST>
58   </REFSECT2>
59
60   <REFSECT2 ID="R2-SQL-CREATEDATABASE-2">
61    <REFSECT2INFO>
62     <DATE>1998-04-15</DATE>
63    </REFSECT2INFO>
64    <TITLE>
65     Outputs
66    </TITLE>
67    <PARA>
68    </PARA>
69    <VARIABLELIST>
70     <VARLISTENTRY>
71      <TERM>
72           <replaceable>status</replaceable>
73      </TERM>
74      <LISTITEM>
75       <PARA>
76        <VARIABLELIST>
77         <VARLISTENTRY>
78          <TERM>
79           <ReturnValue>CREATEDB</ReturnValue>
80          </TERM>
81          <LISTITEM>
82           <PARA>
83           Message returned if the command completes successfully.
84           </PARA>
85          </LISTITEM>
86         </VARLISTENTRY>
87         <VARLISTENTRY>
88          <TERM>
89           <ReturnValue>WARN:  createdb: database "<replaceable class="parameter">name</replaceable>" already exists.</ReturnValue>
90          </TERM>
91          <LISTITEM>
92           <PARA>
93            This occurs if <replaceable class="parameter">database</replaceable> specified already exists.
94           </PARA>
95          </LISTITEM>
96         </VARLISTENTRY>
97         <VARLISTENTRY>
98          <TERM>
99           <ReturnValue>ERROR:  Unable to create database directory <replaceable class="parameter">directory</replaceable>
100 </ReturnValue>
101          </TERM>
102          <LISTITEM>
103           <PARA>
104 There was a problem with creating the required directory; this operation will
105            need permissions for the <literal>postgres</literal> user on the specified location.
106           </PARA>
107          </LISTITEM>
108         </VARLISTENTRY>
109        </variablelist>
110      </LISTITEM>
111     </VARLISTENTRY>
112    </VARIABLELIST>
113   </REFSECT2>
114  </REFSYNOPSISDIV>
115  
116  <REFSECT1 ID="R1-SQL-CREATEDATABASE-1">
117   <REFSECT1INFO>
118    <DATE>1998-04-15</DATE>
119   </REFSECT1INFO>
120   <TITLE>
121    Description
122   </TITLE>
123   <PARA>
124    <command>CREATE DATABASE</command> creates a new Postgres database.
125    The creator becomes the administrator of the new database.
126   </PARA>
127   
128   <REFSECT2 ID="R2-SQL-CREATEDATABASE-3">
129    <REFSECT2INFO>
130     <DATE>1998-04-15</DATE>
131    </REFSECT2INFO>
132    <TITLE>
133     Notes
134    </TITLE>
135    <PARA>
136     <command>CREATE DATABASE</command> is a <productname>Postgres</productname>
137  language extension.
138    </PARA>
139    <para>
140     Use <command>DROP DATABASE</command> to remove a database.
141    </para>
142   </REFSECT2>
143   
144  <REFSECT1 ID="R1-SQL-CREATEDATABASE-2">
145   <TITLE>
146    Usage
147   </TITLE>
148   <PARA>
149    To create a new database:
150   </PARA>
151   <ProgramListing>
152 <prompt>olly=></prompt> <userinput>create database lusiadas;</userinput>
153   </ProgramListing>
154   <PARA>
155    To create a new database in an alternate area <filename>~/private_db</filename>:
156   </PARA>
157   <ProgramListing>
158 <prompt>$</prompt> <userinput>mkdir private_db</userinput>
159 <prompt>$</prompt> <userinput>initlocation ~/private_db</userinput>
160 <computeroutput>Creating Postgres database system directory /home/olly/private_db/base</computeroutput>
161
162 <prompt>$</prompt> <userinput>psql olly</userinput>
163 <computeroutput>Welcome to the POSTGRESQL interactive sql monitor:
164   Please read the file COPYRIGHT for copyright terms of POSTGRESQL
165
166    type \? for help on slash commands
167    type \q to quit
168    type \g or terminate with semicolon to execute query
169  You are currently connected to the database: template1
170
171 <prompt>olly=></prompt></computeroutput> <userinput>create database elsewhere with location = '/home/olly/private_db';</userinput>
172     <computeroutput>CREATEDB</computeroutput>
173   </ProgramListing>
174  </REFSECT1>
175  
176  <REFSECT1 ID="R1-SQL-CREATEDATABASE-3">
177   <TITLE>
178    Bugs
179   </TITLE>
180   <PARA>
181    There are security and data integrity issues
182  involved with using alternate database locations
183    specified with absolute path names, and by default
184 only an environment variable known to the backend may be
185 specified for an alternate location.
186  See the Administrator's Guide for more information.
187   </PARA>
188  </refsect1>
189
190 <!--
191 comment from Olly; response from Thomas...
192   <comment>
193    initlocation does not create a PG_VERSION file in the specified location.
194    How will Postgres handle the situation if it is upgraded to an 
195    incompatible database version?
196   </comment>
197 Hmm. This isn't an issue since the upgrade would do a dump/reload from the main database area also.
198 Not sure if the dump/reload would guarantee that the alternate data area gets refreshed though...
199 -->
200  
201  <REFSECT1 ID="R1-SQL-CREATEDATABASE-4">
202   <TITLE>
203    Compatibility
204   </TITLE>
205   <PARA>
206   
207   <REFSECT2 ID="R2-SQL-CREATEDATABASE-4">
208    <REFSECT2INFO>
209     <DATE>1998-04-15</DATE>
210    </REFSECT2INFO>
211    <TITLE>
212     SQL92
213    </TITLE>
214    <PARA>
215     There is no <command>CREATE DATABASE</command> statement in SQL92.
216    </PARA>
217    <para>
218     The equivalent command in standard SQL is <command>CREATE SCHEMA</command>.
219    </para>
220   </refsect2>
221  </refsect1>
222 </REFENTRY>
223
224
225 <!-- Keep this comment at the end of the file
226 Local variables:
227 mode: sgml
228 sgml-omittag:t
229 sgml-shorttag:t
230 sgml-minimize-attributes:nil
231 sgml-always-quote-attributes:t
232 sgml-indent-step:1
233 sgml-indent-data: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
239 End:
240 -->