1
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
5
>Template Databases</TITLE
8
CONTENT="Modular DocBook HTML Stylesheet Version 1.79"><LINK
10
HREF="mailto:pgsql-docs@postgresql.org"><LINK
12
TITLE="PostgreSQL 9.1beta1 Documentation"
13
HREF="index.html"><LINK
15
TITLE="Managing Databases"
16
HREF="managing-databases.html"><LINK
18
TITLE="Creating a Database"
19
HREF="manage-ag-createdb.html"><LINK
21
TITLE="Database Configuration"
22
HREF="manage-ag-config.html"><LINK
25
HREF="stylesheet.css"><META
26
HTTP-EQUIV="Content-Type"
27
CONTENT="text/html; charset=ISO-8859-1"><META
29
CONTENT="2011-04-27T21:20:33"></HEAD
35
SUMMARY="Header navigation table"
47
>PostgreSQL 9.1beta1 Documentation</A
56
TITLE="Creating a Database"
57
HREF="manage-ag-createdb.html"
66
TITLE="Managing Databases"
67
HREF="managing-databases.html"
74
>Chapter 21. Managing Databases</TD
80
TITLE="Managing Databases"
81
HREF="managing-databases.html"
89
TITLE="Database Configuration"
90
HREF="manage-ag-config.html"
104
NAME="MANAGE-AG-TEMPLATEDBS"
105
>21.3. Template Databases</A
111
> actually works by copying an existing
112
database. By default, it copies the standard system database named
117
database is the <SPAN
120
> from which new databases are
121
made. If you add objects to <TT
125
will be copied into subsequently created user databases. This
126
behavior allows site-local modifications to the standard set of
127
objects in databases. For example, if you install the procedural
135
automatically be available in user databases without any extra
136
action being taken when those databases are created.
139
> There is a second standard system database named
144
database contains the same data as the initial contents of
148
>, that is, only the standard objects
149
predefined by your version of
157
should never be changed after the database cluster has been
158
initialized. By instructing
169
>, you can create a <SPAN
173
database that contains none of the site-local additions in
177
>. This is particularly handy when restoring a
181
> dump: the dump script should be restored in a
182
virgin database to ensure that one recreates the correct contents
183
of the dumped database, without conflicting with objects that
184
might have been added to <TT
190
> Another common reason for copying <TT
197
> is that new encoding and locale settings
198
can be specified when copying <TT
205
> must use the same settings it does.
209
> might contain encoding-specific
210
or locale-specific data, while <TT
216
> To create a database by copying <TT
221
CLASS="PROGRAMLISTING"
227
> TEMPLATE template0;</PRE
229
from the SQL environment, or:
231
CLASS="PROGRAMLISTING"
232
>createdb -T template0 <TT
242
> It is possible to create additional template databases, and indeed
243
one can copy any database in a cluster by specifying its name
244
as the template for <TT
247
>. It is important to
248
understand, however, that this is not (yet) intended as
249
a general-purpose <SPAN
256
The principal limitation is that no other sessions can be connected to
257
the source database while it is being copied. <TT
261
> will fail if any other connection exists when it starts;
262
during the copy operation, new connections to the source database
266
> Two useful flags exist in <TT
270
database: the columns <TT
281
can be set to indicate that a database is intended as a template for
285
>. If this flag is set, the database can be
286
cloned by any user with <TT
289
> privileges; if it is not set,
290
only superusers and the owner of the database can clone it.
294
> is false, then no new connections
295
to that database will be allowed (but existing sessions are not terminated
296
simply by setting the flag false). The <TT
300
database is normally marked <TT
302
>datallowconn = false</TT
303
> to prevent its modification.
311
should always be marked with <TT
313
>datistemplate = true</TT
329
> do not have any special
330
status beyond the fact that the name <TT
334
source database name for <TT
338
For example, one could drop <TT
341
> and recreate it from
345
> without any ill effects. This course of action
346
might be advisable if one has carelessly added a bunch of junk in
356
>pg_database.datistemplate = false</TT
363
> database is also created when a database
364
cluster is initialized. This database is meant as a default database for
365
users and applications to connect to. It is simply a copy of
369
> and can be dropped and recreated if necessary.
379
SUMMARY="Footer navigation table"
390
HREF="manage-ag-createdb.html"
408
HREF="manage-ag-config.html"
418
>Creating a Database</TD
424
HREF="managing-databases.html"
432
>Database Configuration</TD
b'\\ No newline at end of file'