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