]> granicus.if.org Git - postgresql/blob - doc/src/sgml/ref/create_database.sgml
First files for reference pages.
[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    CREATE DATABASE creates a new PostgreSQL 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     CREATE DATABASE statement is a PostgreSQL language extension.
146    </PARA>
147    <para>
148     Refer to DROP DATABASE 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    CREATE DATABASE lusiadas;
161   </ProgramListing>
162   <PARA>
163    To create a new database in <filename>~/private_db</filename>:
164   </PARA>
165   <ProgramListing>
166    $ mkdir private_db
167    $ initlocation ~/private_db
168    <computeroutput>Creating Postgres database system directory /home/olly/private_db/base</computeroutput>
169
170    $ chmod a+rx private_db
171    $ chmod a+rwx private_db/base
172    $ psql 
173    <computeroutput>Welcome to the POSTGRESQL interactive sql monitor:
174      Please read the file COPYRIGHT for copyright terms of POSTGRESQL
175
176       type \? for help on slash commands
177       type \q to quit
178       type \g or terminate with semicolon to execute query
179     You are currently connected to the database: template1
180
181     template1=></computeroutput> <userinput>create database elsewhere with location = '/home/olly/private_db';</userinput>
182     <computeroutput>CREATEDB</computeroutput>
183   </ProgramListing>
184  </REFSECT1>
185  
186  <REFSECT1 ID="R1-SQL-CREATEDATABASE-3">
187   <TITLE>
188    Bugs
189   </TITLE>
190   <PARA>
191    Where an ordinary user cannot change the ownership of files to other users
192    (which is correct from a security point of view), there is no easy way
193    to give the postgres backend access to files in a  database at a
194    non-standard location without
195    giving similar access to all users.  The situation shown in the usage
196    example makes <filename>/home/olly/private_db</filename> world-accessible.
197   </PARA>
198   <para>
199    If, on the other hand, the user gets the system administrator to give
200    file ownership to the <literal>postgres</literal> superuser and restrict access, he will
201    then be unable to delete the <filename><replaceable>directory</replaceable>/base</filename> directory.
202   </para>
203   <comment>
204    initlocation does not create a PG_VERSION file in the specified location.
205    How will PostgreSQL handle the situation if it is upgraded to an 
206    incompatible database version?
207   </comment>
208  </refsect1>
209  
210  <REFSECT1 ID="R1-SQL-CREATEDATABASE-4">
211   <TITLE>
212    Compatibility
213   </TITLE>
214   <PARA>
215   </PARA>
216   
217   <REFSECT2 ID="R2-SQL-CREATEDATABASE-4">
218    <REFSECT2INFO>
219     <DATE>1998-04-15</DATE>
220    </REFSECT2INFO>
221    <TITLE>
222     SQL92
223    </TITLE>
224    <PARA>
225     There is no <command>CREATE DATABASE</command> statement on SQL92.
226    </PARA>
227    <para>
228     The equivalent command in standard SQL is <command>CREATE SCHEMA</command>.
229    </para>
230   </refsect2>
231  </refsect1>
232 </REFENTRY>
233
234
235 <!-- Keep this comment at the end of the file
236 Local variables:
237 mode: sgml
238 sgml-omittag:t
239 sgml-shorttag:t
240 sgml-minimize-attributes:nil
241 sgml-always-quote-attributes:t
242 sgml-indent-step:1
243 sgml-indent-data:t
244 sgml-parent-document:nil
245 sgml-default-dtd-file:"../reference.ced"
246 sgml-exposed-tags:nil
247 sgml-local-catalogs:"/usr/lib/sgml/catalog"
248 sgml-local-ecat-files:nil
249 End:
250 -->