Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 83bad7c

Browse files
committed
This is my -- hopefully sufficiently portable -- attempt at cleaning out
initdb. No more obscure dependencies on environment variables or paths. It now finds the templates and the right postgres itself (with cmd line options as fallback). It also no longer depends on $USER (su safe), and doesn't advertise that --username allows you to install the db as a different user, since that doesn't work anyway. Also, recovery and cleanup on all errors. Consistent options, clearer documentation. Please take a look at this and adopt it if you feel it's safe enough. I have simulated all the stupid circumstances I could think of, but you never know with shell scripts. Oh yeah, you can give the postgres user a default password now. -- Peter Eisentraut Sernanders väg 10:115
1 parent 1b22a8c commit 83bad7c

File tree

3 files changed

+257
-366
lines changed

3 files changed

+257
-366
lines changed

doc/src/sgml/ref/initdb.sgml

Lines changed: 111 additions & 155 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.5 1999/07/22 15:09:12 thomas Exp $
2+
$Header: /cvsroot/pgsql/doc/src/sgml/ref/initdb.sgml,v 1.6 1999/12/17 01:05:29 momjian Exp $
33
Postgres documentation
44
-->
55

@@ -15,24 +15,26 @@ Postgres documentation
1515
<application>initdb</application>
1616
</refname>
1717
<refpurpose>
18-
Create a new <productname>Postgres</productname> database installation
18+
Create a new <productname>PostgreSQL</productname> database installation
1919
</refpurpose>
2020
</refnamediv>
2121
<refsynopsisdiv>
2222
<refsynopsisdivinfo>
23-
<date>1999-07-20</date>
23+
<date>1999-12-17</date>
2424
</refsynopsisdivinfo>
2525
<synopsis>
26-
initdb [ --pgdata=<replaceable class="parameter">dbdir</replaceable> | -r <replaceable class="parameter">dbdir</replaceable> ]
27-
[ --pglib=<replaceable class="parameter">libdir</replaceable> | -l <replaceable class="parameter">libdir</replaceable> ]
28-
[ --template=<replaceable class="parameter">template</replaceable> | -t <replaceable class="parameter">template</replaceable> ]
29-
[ --username=<replaceable class="parameter">name</replaceable> | -u <replaceable class="parameter">name</replaceable> ]
30-
[ --noclean | -n ] [ --debug | -d ]
26+
initdb [ --pgdata|-D <replaceable class="parameter">dbdir</replaceable> ]
27+
[ --sysid|-i <replaceable class="parameter">sysid</replaceable> ]
28+
[ --password|-W <replaceable class="parameter">password</replaceable> ]
29+
[ --pgencoding|-e <replaceable class="parameter">encoding</replaceable> ]
30+
[ --pglib|-L <replaceable class="parameter">libdir</replaceable> ]
31+
[ --username|-u <replaceable class="parameter">name</replaceable> ]
32+
[ --noclean | -n ] [ --debug | -d ] [ --template | -t ]
3133
</synopsis>
3234

3335
<refsect2 id="R2-APP-INITDB-1">
3436
<refsect2info>
35-
<date>1998-10-02</date>
37+
<date>1999-11-17</date>
3638
</refsect2info>
3739
<title>
3840
Inputs
@@ -41,78 +43,108 @@ initdb [ --pgdata=<replaceable class="parameter">dbdir</replaceable> | -r <repla
4143

4244
<variablelist>
4345
<varlistentry>
44-
<term>--pglib=<replaceable class="parameter">libdir</replaceable></term>
45-
<term>-l <replaceable class="parameter">libdir</replaceable></term>
46-
<term><envar>PGLIB</envar></term>
46+
<term>--pgdata=<replaceable class="parameter">dbdir</replaceable></term>
47+
<term>-D <replaceable class="parameter">dbdir</replaceable></term>
48+
<term><envar>PGDATA</envar></term>
4749
<listitem>
4850
<para>
49-
Where are the files that make up <productname>Postgres</productname>?
50-
Apart from files that
51-
have to go in particular directories because of their function, the
52-
files that make up the <productname>Postgres</productname> software
53-
were installed in a directory
54-
called the <replaceable class="parameter">libdir</replaceable> directory.
55-
An example of a file that will be found
56-
there that <application>initdb</application>
57-
needs is <filename>global1.bki.source</filename>,
58-
which contains all the information that goes
59-
into the shared catalog tables.
51+
This option specifies where in the file system the database should be
52+
stored. This is the only information required by initdb, but you can avoid
53+
it by setting the <envar>PGDATA</envar> environment variable, which
54+
can be convenient since the database server (<filename>postmaster</filename>)
55+
can find the database directory later by the same variable.
6056
</para>
6157
</listitem>
6258
</varlistentry>
6359

6460
<varlistentry>
65-
<term>--pgdata=<replaceable class="parameter">dbdir</replaceable></term>
66-
<term>-r <replaceable class="parameter">dbdir</replaceable></term>
67-
<term><envar>PGDATA</envar></term>
61+
<term>--sysid=<replaceable class="parameter">sysid</replaceable></term>
62+
<term>-i <replaceable class="parameter">sysid</replaceable></term>
6863
<listitem>
6964
<para>
70-
Where in your Unix filesystem do you want the database data to go?
71-
The top level directory is called the <envar>PGDATA</envar> directory.
65+
Selects the system id of the database superuser. This defaults to
66+
the effective user id of the user running initdb. It is really
67+
not important what the superuser's sysid is, but one might choose
68+
to start the numbering at some number like 0 or 1.
7269
</para>
7370
</listitem>
7471
</varlistentry>
75-
72+
7673
<varlistentry>
77-
<term>--username=<replaceable class="parameter">name</replaceable></term>
78-
<term>-u <replaceable class="parameter">name</replaceable></term>
79-
<term><envar>PGUSER</envar></term>
74+
<term>--password=<replaceable class="parameter">password</replaceable></term>
75+
<term>-W <replaceable class="parameter">password</replaceable></term>
8076
<listitem>
8177
<para>
82-
Who will be the <productname>Postgres</productname> superuser
83-
for this database system? The
84-
<productname>Postgres</productname> superuser is a Unix user
85-
who owns all files that store the database
86-
system and also owns the postmaster and backend processes that access them.
87-
Or just let it default to you (the Unix user who runs
88-
<application>initdb</application>).
78+
Sets the password of the database superuser. If you don't plan
79+
on using password authentication, this is not important. If you
80+
do, you can save yourself a trip by specifying it here, but you
81+
can always change it later. The default password is empty.
8982
</para>
90-
<note>
91-
<para>
92-
Only the Unix superuser (<literal>root</literal>)
93-
can create a database system with an owner
94-
different from the <productname>Postgres</productname> superuser.
95-
</para>
96-
</note>
9783
</listitem>
9884
</varlistentry>
99-
</variablelist>
85+
86+
<varlistentry>
87+
<term>--pgencoding=<replaceable class="parameter">encoding</replaceable></term>
88+
<term>-e <replaceable class="parameter">encoding</replaceable></term>
89+
<listitem>
90+
<para>
91+
Selects the multibyte encoding of the template database. This will also
92+
be the default encoding of any database you create later, unless you
93+
override it there. To use the multibyte encoding feature, you must
94+
specify so at build time, at which time you also select the default
95+
for this option.
96+
</para>
97+
</listitem>
98+
</varlistentry>
99+
100+
</variablelist>
100101
</para>
101102

102103
<para>
103104
Other, less commonly used, parameters are also available:
104105

105106
<variablelist>
106107
<varlistentry>
107-
<term>--template=<replaceable class="parameter">template</replaceable></term>
108-
<term>-t <replaceable class="parameter">template</replaceable></term>
108+
<term>--pglib=<replaceable class="parameter">libdir</replaceable></term>
109+
<term>-l <replaceable class="parameter">libdir</replaceable></term>
110+
<listitem>
111+
<para>
112+
initdb needs a few input files to initialize the database. This option
113+
tells where to find them. You normally don't have to worry about this
114+
since initdb knows about the most common installation layouts and will
115+
find the files itself. You will be told if you need to specify their
116+
location explicitly. If that happens, one of the files is called
117+
<filename>global1.bki.source</filename> and is traditionally installed
118+
along with the others in the library directory (e.g.,
119+
<filename>/usr/local/pgsql/lib</filename>).
120+
</para>
121+
</listitem>
122+
</varlistentry>
123+
124+
<varlistentry>
125+
<term>--username=<replaceable class="parameter">name</replaceable></term>
126+
<term>-u <replaceable class="parameter">name</replaceable></term>
127+
<listitem>
128+
<para>
129+
The database system will be initialized with the username that is
130+
running initdb. That is a requirement. If for some unimaginable
131+
reason initdb cannot find out what the current user's name is,
132+
you have to use this option. Normally, this will not be necessary
133+
and initdb will tell you when it is.
134+
</para>
135+
</listitem>
136+
</varlistentry>
137+
138+
<varlistentry>
139+
<term>--template</term>
140+
<term>-t</term>
109141
<listitem>
110142
<para>
111143
Replace the <literal>template1</literal>
112144
database in an existing database system, and don't touch anything else.
113145
This is useful when you need to upgrade your <literal>template1</literal>
114146
database using <application>initdb</application>
115-
from a newer release of <productname>Postgres</productname>,
147+
from a newer release of <productname>PostgreSQL</productname>,
116148
or when your <literal>template1</literal>
117149
database has become corrupted by some system problem. Normally the
118150
contents of <literal>template1</literal>
@@ -133,8 +165,7 @@ initdb [ --pgdata=<replaceable class="parameter">dbdir</replaceable> | -r <repla
133165
By default, when <application>initdb</application>
134166
determines that error prevent it from completely creating the database
135167
system, it removes any files it may have created before determining
136-
that it can't finish the job. That includes any core files left by
137-
the programs it invokes. This option inhibits any tidying-up and is
168+
that it can't finish the job. This option inhibits any tidying-up and is
138169
thus useful for debugging.
139170
</para>
140171
</listitem>
@@ -145,67 +176,29 @@ initdb [ --pgdata=<replaceable class="parameter">dbdir</replaceable> | -r <repla
145176
<term>-d</term>
146177
<listitem>
147178
<para>
148-
Print debugging output from the bootstrap backend.
179+
Print debugging output from the bootstrap backend and a few other
180+
messages of lesser interest for the general public.
149181
The bootstrap backend is the program <application>initdb</application>
150182
uses to create the catalog tables. This option generates a tremendous
151-
amount of output. It also turns off the final vacuuming step.
183+
amount of output.
152184
</para>
153185
</listitem>
154186
</varlistentry>
155187

156188
</variablelist>
157189
</para>
158190

159-
<para>
160-
Files are also input to <application>initdb</application>:
161-
162-
<variablelist>
163-
<varlistentry>
164-
<term><application>postconfig</application></term>
165-
<listitem>
166-
<para>
167-
If appearing somewhere in the Unix command search path
168-
(defined by the PATH environment variable).
169-
This is a program that specifies defaults for some of the
170-
command options. See below.
171-
</para>
172-
</listitem>
173-
</varlistentry>
174-
175-
<varlistentry>
176-
<term><filename><envar>PGLIB</envar>/global1.bki.source</filename></term>
177-
<listitem>
178-
<para>
179-
Contents for the shared catalog tables in the new database system. This
180-
file is part of the <productname>Postgres</productname> software.
181-
</para>
182-
</listitem>
183-
</varlistentry>
184-
185-
<varlistentry>
186-
<term><filename><envar>PGLIB</envar>/local1_template1.bki.source</filename></term>
187-
<listitem>
188-
<para>
189-
Contents for the template1 tables in the new database system. This
190-
file is part of the <productname>Postgres</productname> software.
191-
</para>
192-
</listitem>
193-
</varlistentry>
194-
195-
</variablelist>
196-
</para>
197191
</refsect2>
198192

199193
<refsect2 id="R2-APP-INITDB-2">
200194
<refsect2info>
201-
<date>1998-09-26</date>
195+
<date>1999-12-17</date>
202196
</refsect2info>
203197
<title>
204198
Outputs
205199
</title>
206200
<para>
207-
<application>initdb</application> will create files in the
208-
<envar>PGDATA</envar>
201+
<application>initdb</application> will create files in the specified
209202
data area which are the system tables and framework for a complete
210203
installation.
211204
</para>
@@ -214,14 +207,14 @@ initdb [ --pgdata=<replaceable class="parameter">dbdir</replaceable> | -r <repla
214207

215208
<refsect1 id="R1-APP-INITDB-1">
216209
<refsect1info>
217-
<date>1998-09-26</date>
210+
<date>1999-12-17</date>
218211
</refsect1info>
219212
<title>
220213
Description
221214
</title>
222215
<para>
223216
<application>initdb</application> creates a new
224-
<productname>Postgres</productname> database system.
217+
<productname>PostgreSQL</productname> database system.
225218
A database system is a
226219
collection of databases that are all administered by the same Unix user
227220
and managed by a single postmaster.
@@ -231,74 +224,37 @@ initdb [ --pgdata=<replaceable class="parameter">dbdir</replaceable> | -r <repla
231224
the database data will live, generating the shared catalog tables
232225
(tables that don't belong to any particular database), and
233226
creating the <literal>template1</literal>
234-
database. What is the <literal>template1</literal>
235-
database? When you create a database, <productname>Postgres</productname>
236-
does it by copying
237-
everything from the <literal>template1</literal>
238-
database. It contains catalog tables filled in for things like the
227+
database. When you create a new database, everything in the
228+
<literal>template1</literal> database is copied.
229+
It contains catalog tables filled in for things like the
239230
builtin types.
240231
</para>
241-
<para>
242-
After <application>initdb</application>
243-
creates the database, it completes the initialization by running
244-
<application>vacuum</application>, which resets some optimization parameters.
245-
</para>
246-
<para>
247-
There are three ways to give parameters to <application>initdb</application>.
248232

249-
<itemizedlist>
250-
<listitem>
251-
<para>
252-
You can use <application>initdb</application> command options.
253-
</para>
254-
</listitem>
255-
<listitem>
256-
<para>
257-
You can set environment
258-
variables before invoking <application>initdb</application>.
259-
</para>
260-
</listitem>
261-
262-
<listitem>
263-
<para>
264-
You can have a program called <application>postconfig</application>
265-
in your Unix command search path.
266-
<application>initdb</application> invokes that program and that program then writes
267-
<application>initdb</application> parameters to its standard output stream.
268-
This third option is not a common thing to do, however.
269-
</para>
270-
</listitem>
271-
</itemizedlist>
233+
<para>
234+
You must not execute <application>initdb</application> as root. This is
235+
because you cannot run the database server as root either, but the
236+
server needs to have access to the files <application>initdb</application>
237+
creates. Furthermore, during the initialization phase, when there are no
238+
users and no access controls installed, postgres will only connect with
239+
the name of the current Unix user, so you must log in under the account
240+
that will own the server process.
272241
</para>
273242

274243
<para>
275-
Command options always override parameters specified any other way.
276-
The values returned by <application>postconfig</application>
277-
override any environment variables, but your
278-
<application>postconfig</application>
279-
program may base its output on the environment variables if you want
280-
their values to be used.
244+
Although <application>initdb</application> will attempt to create the respective
245+
data directory, chances are that it won't have the permission to do so. Thus
246+
it is a good idea to create the data directory before running <application>initdb</application>
247+
<emphasis>and</emphasis> to hand over the ownership of it to the database superuser.
281248
</para>
282249

283250
<para>
284-
The value that <application>postconfig</application>
285-
outputs must have the format
286-
<synopsis>
287-
<replaceable>var1</replaceable>=<replaceable class="parameter">value1</replaceable> <replaceable class="parameter">var2</replaceable>=<replaceable class="parameter">value2</replaceable> ...
288-
</synopsis>
289-
290-
It can output nothing if it doesn't want to supply any parameters.
291-
The <replaceable>var</replaceable> values are equal to
292-
the corresponding environment variable
293-
names. For example,
294-
<programlisting>
295-
PGDATA=/tmp/postgres_test
296-
</programlisting>
297-
has the
298-
same effect as invoking <application>initdb</application>
299-
with an environment variable called <envar>PGDATA</envar> whose value is
300-
<filename>/tmp/postgres_test</filename>.
251+
Note that if you use the <option>--username</option> you must give correct
252+
information about the name of the <emphasis>current</emphasis> user. If you don't
253+
this will usually manifest itself in an error message about <literal>chmod</literal>
254+
failing on a file <filename>pg_pwd</filename>, because the backend silently
255+
refuses to create it.
301256
</para>
257+
302258
</refsect1>
303259
</refentry>
304260

0 commit comments

Comments
 (0)