1
1
<!--
2
- $Header: /cvsroot/pgsql/doc/src/sgml/ref/create_database.sgml,v 1.15 2000/10/05 19:48:17 momjian Exp $
2
+ $Header: /cvsroot/pgsql/doc/src/sgml/ref/create_database.sgml,v 1.16 2000/11/14 18:37:40 tgl Exp $
3
3
Postgres documentation
4
4
-->
5
5
@@ -23,7 +23,10 @@ Postgres documentation
23
23
<date>1999-12-11</date>
24
24
</refsynopsisdivinfo>
25
25
<synopsis>
26
- CREATE DATABASE <replaceable class="PARAMETER">name</replaceable> [ WITH LOCATION = '<replaceable class="parameter">dbpath</replaceable>' ]
26
+ CREATE DATABASE <replaceable class="PARAMETER">name</replaceable>
27
+ [ WITH [ LOCATION = '<replaceable class="parameter">dbpath</replaceable>' ]
28
+ [ TEMPLATE = <replaceable class="parameter">template</replaceable> ]
29
+ [ ENCODING = <replaceable class="parameter">encoding</replaceable> ] ]
27
30
</synopsis>
28
31
29
32
<refsect2 id="R2-SQL-CREATEDATABASE-1">
@@ -48,8 +51,30 @@ CREATE DATABASE <replaceable class="PARAMETER">name</replaceable> [ WITH LOCATIO
48
51
<term><replaceable class="parameter">dbpath</replaceable></term>
49
52
<listitem>
50
53
<para>
51
- An alternate location where to store the new database in the filesystem.
52
- See below for caveats.
54
+ An alternate filesystem location in which to store the new database,
55
+ specified as a string literal;
56
+ or <literal>DEFAULT</literal> to use the default location.
57
+ </para>
58
+ </listitem>
59
+ </varlistentry>
60
+ <varlistentry>
61
+ <term><replaceable class="parameter">template</replaceable></term>
62
+ <listitem>
63
+ <para>
64
+ Name of template from which to create the new database,
65
+ or <literal>DEFAULT</literal> to use the default template
66
+ (<literal>template1</literal>).
67
+ </para>
68
+ </listitem>
69
+ </varlistentry>
70
+ <varlistentry>
71
+ <term><replaceable class="parameter">encoding</replaceable></term>
72
+ <listitem>
73
+ <para>
74
+ Multibyte encoding method to use in the new database. Specify
75
+ a string literal name (e.g., <literal>'SQL_ASCII'</literal>),
76
+ or an integer encoding number, or <literal>DEFAULT</literal>
77
+ to use the default encoding.
53
78
</para>
54
79
</listitem>
55
80
</varlistentry>
@@ -98,11 +123,10 @@ CREATE DATABASE <replaceable class="PARAMETER">name</replaceable> [ WITH LOCATIO
98
123
</varlistentry>
99
124
100
125
<varlistentry>
101
- <term><computeroutput>ERROR: Single quotes are not allowed in database names.</computeroutput></term>
102
- <term><computeroutput>ERROR: Single quotes are not allowed in database paths.</computeroutput></term>
126
+ <term><computeroutput>ERROR: database path may not contain single quotes</computeroutput></term>
103
127
<listitem>
104
128
<para>
105
- The database <replaceable class="parameter">name</replaceable> and
129
+ The database location
106
130
<replaceable class="parameter">dbpath</replaceable> cannot contain
107
131
single quotes. This is required so that the shell commands that
108
132
create the database directory can execute safely.
@@ -111,18 +135,7 @@ CREATE DATABASE <replaceable class="PARAMETER">name</replaceable> [ WITH LOCATIO
111
135
</varlistentry>
112
136
113
137
<varlistentry>
114
- <term><computeroutput>ERROR: The path 'xxx' is invalid.</computeroutput></term>
115
- <listitem>
116
- <para>
117
- The expansion of the specified <replaceable class="parameter">dbpath</replaceable>
118
- (see below) failed. Check the path you entered or make sure that the
119
- environment variable you are referencing does exist.
120
- </para>
121
- </listitem>
122
- </varlistentry>
123
-
124
- <varlistentry>
125
- <term><computeroutput>ERROR: createdb: May not be called in a transaction block.</computeroutput></term>
138
+ <term><computeroutput>ERROR: CREATE DATABASE: may not be called in a transaction block</computeroutput></term>
126
139
<listitem>
127
140
<para>
128
141
If you have an explicit transaction block in progress you cannot call
@@ -133,6 +146,9 @@ CREATE DATABASE <replaceable class="PARAMETER">name</replaceable> [ WITH LOCATIO
133
146
134
147
<varlistentry>
135
148
<term><computeroutput>ERROR: Unable to create database directory '<replaceable>path</replaceable>'.</computeroutput></term>
149
+ </varlistentry>
150
+
151
+ <varlistentry>
136
152
<term><computeroutput>ERROR: Could not initialize database directory.</computeroutput></term>
137
153
<listitem>
138
154
<para>
@@ -169,10 +185,10 @@ CREATE DATABASE <replaceable class="PARAMETER">name</replaceable> [ WITH LOCATIO
169
185
command.
170
186
</para>
171
187
<para>
172
- If the path contains a slash, the leading part is interpreted
173
- as an environment variable, which must be known to the
188
+ If the path name does not contain a slash, it is interpreted
189
+ as an environment variable name , which must be known to the
174
190
server process. This way the database administrator can
175
- exercise control over at which locations databases can be created.
191
+ exercise control over locations in which databases can be created.
176
192
(A customary choice is, e.g., '<envar>PGDATA2</envar>'.)
177
193
If the server is compiled with <literal>ALLOW_ABSOLUTE_DBPATHS</literal>
178
194
(not so by default), absolute path names, as identified by
@@ -181,6 +197,29 @@ CREATE DATABASE <replaceable class="PARAMETER">name</replaceable> [ WITH LOCATIO
181
197
are allowed as well.
182
198
</para>
183
199
200
+ <para>
201
+ By default, the new database will be created by cloning the standard
202
+ system database <literal>template1</>. A different template can be
203
+ specified by writing <literal>TEMPLATE =</>
204
+ <replaceable class="parameter">name</replaceable>. In particular,
205
+ by writing <literal>TEMPLATE = template0</>, you can create a virgin
206
+ database containing only the standard objects predefined by your
207
+ version of Postgres. This is useful if you wish to avoid copying
208
+ any installation-local objects that may have been added to template1.
209
+ </para>
210
+
211
+ <para>
212
+ The optional encoding parameter allows selection of the database encoding,
213
+ if your server was compiled with multibyte encoding support. When not
214
+ specified, it defaults to the encoding used by the selected template
215
+ database.
216
+ </para>
217
+
218
+ <para>
219
+ Optional parameters can be written in any order, not only the order
220
+ illustrated above.
221
+ </para>
222
+
184
223
<refsect2 id="R2-SQL-CREATEDATABASE-3">
185
224
<refsect2info>
186
225
<date>1999-12-11</date>
@@ -221,6 +260,33 @@ comment from Olly; response from Thomas...
221
260
Not sure if the dump/reload would guarantee that
222
261
the alternate data area gets refreshed though...
223
262
-->
263
+
264
+ <para>
265
+ Although it is possible to copy a database other than template1 by
266
+ specifying its name as the template, this is not (yet) intended as
267
+ a general-purpose COPY DATABASE facility. In particular, it is
268
+ essential that the source database be idle (no data-altering transactions
269
+ in progress)
270
+ for the duration of the copying operation. CREATE DATABASE will check
271
+ that no backend processes (other than itself) are connected to
272
+ the source database at the start of the operation, but this does not
273
+ guarantee that changes cannot be made while the copy proceeds. Therefore,
274
+ we recommend that databases used as templates be treated as read-only.
275
+ </para>
276
+
277
+ <para>
278
+ Two useful flags exist in <literal>pg_database</literal> for each
279
+ database: <literal>datistemplate</literal> and
280
+ <literal>datallowconn</literal>. <literal>datistemplate</literal>
281
+ may be set to indicate that a database is intended as a template for
282
+ CREATE DATABASE. If this flag is set, the database may be cloned by
283
+ any user with CREATEDB privileges; if it is not set, only superusers
284
+ and the owner of the database may clone it.
285
+ If <literal>datallowconn</literal> is false, then no new connections
286
+ to that database will be allowed (but existing sessions are not killed
287
+ simply by setting the flag false). The <literal>template0</literal>
288
+ database is normally marked this way to prevent modification of it.
289
+ </para>
224
290
</refsect2>
225
291
</refsect1>
226
292
0 commit comments