Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commita2405d5

Browse files
committed
Get rid of initdb -t bugs by the simple expedient of getting rid of
initdb -t. This option is obsoleted by 7.1's ability to drop andrecreate template1 during normal operation.
1 parent74bbe80 commita2405d5

File tree

2 files changed

+49
-84
lines changed

2 files changed

+49
-84
lines changed

‎doc/src/sgml/ref/initdb.sgml

Lines changed: 19 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$Header: /cvsroot/pgsql/doc/src/sgml/ref/initdb.sgml,v 1.14 2000/12/25 23:15:26 petere Exp $
2+
$Header: /cvsroot/pgsql/doc/src/sgml/ref/initdb.sgml,v 1.15 2001/01/20 22:09:24 tgl Exp $
33
Postgres documentation
44
-->
55

@@ -41,7 +41,6 @@ Postgres documentation
4141
<arg>-L <replaceable>directory</replaceable></arg>
4242
<group><arg>--noclean</arg><arg>-n</arg></group>
4343
<group><arg>--debug</arg><arg>-d</arg></group>
44-
<group><arg>--template</arg><arg>-t</arg></group>
4544
</cmdsynopsis>
4645
</refsynopsisdiv>
4746

@@ -58,17 +57,18 @@ Postgres documentation
5857
<para>
5958
Creating a database system consists of creating the directories in which
6059
the database data will live, generating the shared catalog tables
61-
(tables thatdo not belongto any particular database), and
62-
creating the <literal>template1</literal>
60+
(tables thatbelong to the whole cluster rather thanto any particular
61+
database), andcreating the <literal>template1</literal>
6362
database. When you create a new database, everything in the
6463
<literal>template1</literal> database is copied.
6564
It contains catalog tables filled in for things like the
6665
built-in types.
6766
</para>
6867

6968
<para>
70-
You must not execute <application>initdb</application> as root. This is
71-
because you cannot run the database server as root either, but the
69+
You must not execute <application>initdb</application> as root; it must
70+
be run by the Unix user account that will run the database server.
71+
This is because you cannot run the database server as root either, but the
7272
server needs to have access to the files <application>initdb</application>
7373
creates. Furthermore, during the initialization phase, when there are no
7474
users and no access controls installed, <productname>Postgres</productname>
@@ -78,10 +78,14 @@ Postgres documentation
7878
</para>
7979

8080
<para>
81-
Although <application>initdb</application> will attempt to create the respective
82-
data directory, chances are that it won't have the permission to do so. Thus
83-
it is a good idea to create the data directory before running <application>initdb</application>
84-
<emphasis>and</emphasis> to hand over the ownership of it to the database superuser.
81+
Although <application>initdb</application> will attempt to create the
82+
specified data directory, often it won't have permission to do so,
83+
since the parent of the desired data directory is often a root-owned
84+
directory. To set up an arrangement like this, create an empty data
85+
directory as root, then use <application>chown</application> to hand over
86+
ownership of that directory to the database user account, then
87+
<application>su</application> to become the database user, and
88+
finally run <application>initdb</application> as the database user.
8589
</para>
8690

8791
<refsect2>
@@ -96,7 +100,7 @@ Postgres documentation
96100
<para>
97101
This option specifies where in the file system the database
98102
should be stored. This is the only information required by
99-
<application>initdb</application>, but you can avoid it by
103+
<application>initdb</application>, but you can avoidwritingit by
100104
setting the <envar>PGDATA</envar> environment variable, which
101105
can be convenient since the database server
102106
(<filename>postmaster</filename>) can find the database
@@ -125,7 +129,7 @@ Postgres documentation
125129
<listitem>
126130
<para>
127131
Makes <application>initdb</application> prompt for a password
128-
of the database superuser. If you don't plan on using password
132+
to give the database superuser. If you don't plan on using password
129133
authentication, this is not important. Otherwise you won't be
130134
able to use password authentication until you have a password
131135
set up.
@@ -166,37 +170,15 @@ Postgres documentation
166170
</listitem>
167171
</varlistentry>
168172

169-
<varlistentry>
170-
<term>--template</term>
171-
<term>-t</term>
172-
<listitem>
173-
<para>
174-
Replace the <literal>template1</literal>
175-
database in an existing database system, and don't touch anything else.
176-
This is useful when you need to upgrade your <literal>template1</literal>
177-
database using <application>initdb</application>
178-
from a newer release of <productname>Postgres</productname>,
179-
or when your <literal>template1</literal>
180-
database has become corrupted by some system problem. Normally the
181-
contents of <literal>template1</literal>
182-
remain constant throughout the life of the database system. You can't
183-
destroy anything by running <application>initdb</application>
184-
with the
185-
<option>--template</option>
186-
option.
187-
</para>
188-
</listitem>
189-
</varlistentry>
190-
191173
<varlistentry>
192174
<term>--noclean</term>
193175
<term>-n</term>
194176
<listitem>
195177
<para>
196178
By default, when <application>initdb</application>
197179
determines that an error prevented it from completely creating the database
198-
system, it removes any files it may have created beforedetermining
199-
that it can't finish the job. This option inhibitsanytidying-up and is
180+
system, it removes any files it may have created beforediscovering
181+
that it can't finish the job. This option inhibits tidying-up and is
200182
thus useful for debugging.
201183
</para>
202184
</listitem>
@@ -211,7 +193,7 @@ Postgres documentation
211193
messages of lesser interest for the general public.
212194
The bootstrap backend is the program <application>initdb</application>
213195
uses to create the catalog tables. This option generates a tremendous
214-
amount of output.
196+
amount ofextremely boringoutput.
215197
</para>
216198
</listitem>
217199
</varlistentry>

‎src/bin/initdb/initdb.sh

Lines changed: 30 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,14 @@
1515
# changed to add site-local standard data. Either one can be copied
1616
# to produce a new database.
1717
#
18-
# Optionally, we can skip creating the complete database cluster and
19-
# just create (or replace) the template databases.
20-
#
21-
# To create all those things, we run the postgres (backend) program and
22-
# feed it data from the bki files that were installed.
18+
# To create template1, we run the postgres (backend) program and
19+
# feed it data from the bki files that were installed. template0 is
20+
# made just by copying the completed template1.
2321
#
2422
#
2523
# Copyright (c) 1994, Regents of the University of California
2624
#
27-
# $Header: /cvsroot/pgsql/src/bin/initdb/Attic/initdb.sh,v 1.119 2001/01/04 17:25:09 petere Exp $
25+
# $Header: /cvsroot/pgsql/src/bin/initdb/Attic/initdb.sh,v 1.120 2001/01/20 22:09:24 tgl Exp $
2826
#
2927
#-------------------------------------------------------------------------
3028

@@ -38,7 +36,7 @@ exit_nicely(){
3836
echo1>&2
3937
echo"$CMDNAME failed."1>&2
4038
if ["$noclean"!= yes ];then
41-
if ["$template_only"!= yes ]&& ["$made_new_pgdata"= yes ];then
39+
if ["$made_new_pgdata"= yes ];then
4240
echo"Removing$PGDATA."1>&2
4341
rm -rf"$PGDATA"||echo"Failed."1>&2
4442
fi
@@ -169,7 +167,6 @@ MULTIBYTEID=0
169167
# Set defaults:
170168
debug=
171169
noclean=
172-
template_only=
173170
show_setting=
174171

175172
# Note: There is a single compelling reason that the name of the database
@@ -202,10 +199,6 @@ do
202199
noclean=yes
203200
echo"Running with noclean mode on. Mistakes will not be cleaned up."
204201
;;
205-
--template|-t)
206-
template_only=yes
207-
echo"Updating template0 and template1 databases only."
208-
;;
209202
# The sysid of the database superuser. Can be freely changed.
210203
--sysid|-i)
211204
POSTGRES_SUPERUSERID="$2"
@@ -232,7 +225,7 @@ do
232225
-D*)
233226
PGDATA=`echo$1| sed's/^-D//'`
234227
;;
235-
# The directory where thedatabase templates are stored. Normally
228+
# The directory where the.bki input files are stored. Normally
236229
# they are in PREFIX/share and this option should be unnecessary.
237230
-L)
238231
datadir="$2"
@@ -278,7 +271,6 @@ if [ "$usage" ]; then
278271
echo" -i, --sysid SYSID Database sysid for the superuser"
279272
echo"Less commonly used options:"
280273
echo" -L DIRECTORY Where to find the input files"
281-
echo" -t, --template Re-initialize template databases only"
282274
echo" -d, --debug Generate lots of debugging output"
283275
echo" -n, --noclean Do not clean up after errors"
284276
echo
@@ -400,16 +392,13 @@ umask 077
400392
pgdata_contents=`ls -A"$PGDATA"2>/dev/null`
401393
if [ x"$pgdata_contents"!= x ]
402394
then
403-
if ["$template_only"!= yes ]
404-
then
405-
(
406-
echo"$CMDNAME: The directory$PGDATA exists but is not empty."
407-
echo"If you want to create a new database system, either remove or empty"
408-
echo"the directory$PGDATA or run initdb with an argument"
409-
echo"other than$PGDATA."
410-
)1>&2
411-
exit 1
412-
fi
395+
(
396+
echo"$CMDNAME: The directory$PGDATA exists but is not empty."
397+
echo"If you want to create a new database system, either remove or empty"
398+
echo"the directory$PGDATA or run initdb with"
399+
echo"an argument other than$PGDATA."
400+
)1>&2
401+
exit 1
413402
else
414403
if [!-d"$PGDATA" ];then
415404
echo"Creating directory$PGDATA"
@@ -470,31 +459,25 @@ echo $short_version > "$PGDATA"/base/1/PG_VERSION || exit_nicely
470459
#
471460
# CREATE GLOBAL TABLES
472461
#
473-
# XXX --- I do not believe the "template_only" option can actually work.
474-
# With this coding, it'll fail to make entries for pg_shadow etc. in
475-
# template1 ... tgl 11/2000
476462

477-
if ["$template_only"!= yes ]
478-
then
479-
echo"Creating global relations in$PGDATA/global"
480-
["$debug"= yes ]&&echo"Running:$PGPATH/postgres$BACKENDARGS template1"
481-
482-
cat"$GLOBAL_BKI" \
483-
| sed -e"s/POSTGRES/$POSTGRES_SUPERUSERNAME/g" \
484-
-e"s/PGUID/$POSTGRES_SUPERUSERID/g" \
485-
-e"s/ENCODING/$MULTIBYTEID/g" \
486-
|"$PGPATH"/postgres$BACKENDARGS template1 \
487-
|| exit_nicely
488-
489-
echo$short_version>"$PGDATA/PG_VERSION"|| exit_nicely
490-
491-
cp"$PG_HBA_SAMPLE""$PGDATA"/pg_hba.conf|| exit_nicely
492-
cp"$PG_IDENT_SAMPLE""$PGDATA"/pg_ident.conf|| exit_nicely
493-
cp"$POSTGRESQL_CONF_SAMPLE""$PGDATA"/postgresql.conf|| exit_nicely
494-
chmod 0600"$PGDATA"/pg_hba.conf"$PGDATA"/pg_ident.conf \
495-
"$PGDATA"/postgresql.conf
463+
echo"Creating global relations in$PGDATA/global"
496464

497-
fi
465+
["$debug"= yes ]&&echo"Running:$PGPATH/postgres$BACKENDARGS template1"
466+
467+
cat"$GLOBAL_BKI" \
468+
| sed -e"s/POSTGRES/$POSTGRES_SUPERUSERNAME/g" \
469+
-e"s/PGUID/$POSTGRES_SUPERUSERID/g" \
470+
-e"s/ENCODING/$MULTIBYTEID/g" \
471+
|"$PGPATH"/postgres$BACKENDARGS template1 \
472+
|| exit_nicely
473+
474+
echo$short_version>"$PGDATA/PG_VERSION"|| exit_nicely
475+
476+
cp"$PG_HBA_SAMPLE""$PGDATA"/pg_hba.conf|| exit_nicely
477+
cp"$PG_IDENT_SAMPLE""$PGDATA"/pg_ident.conf|| exit_nicely
478+
cp"$POSTGRESQL_CONF_SAMPLE""$PGDATA"/postgresql.conf|| exit_nicely
479+
chmod 0600"$PGDATA"/pg_hba.conf"$PGDATA"/pg_ident.conf \
480+
"$PGDATA"/postgresql.conf
498481

499482

500483
##########################################################################

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp