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

Commit 54ca7a7

Browse files
committed
(Now featuring documentation: fixed some typos, expanded the
Envrironment and Files section, explained exactly what -w does) This is a patch which allows pg_ctl to make an intelligent guess as to the proper port when running 'psql -l' to determine if the database has started up (the -w flag). The environment variable PGPORT is used. If that is not found, it checks if a specific port has been set inside the postgresql.conf file. If it is has not, it uses the port that Postgres was compiled with. Greg Sabino Mullane greg@turnstep.com
1 parent 3c28f9c commit 54ca7a7

File tree

3 files changed

+114
-39
lines changed

3 files changed

+114
-39
lines changed

doc/src/sgml/ref/pg_ctl-ref.sgml

Lines changed: 90 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$Header: /cvsroot/pgsql/doc/src/sgml/ref/pg_ctl-ref.sgml,v 1.18 2003/01/19 00:13:30 momjian Exp $
2+
$Header: /cvsroot/pgsql/doc/src/sgml/ref/pg_ctl-ref.sgml,v 1.19 2003/03/20 05:00:14 momjian Exp $
33
PostgreSQL documentation
44
-->
55

@@ -73,22 +73,21 @@ PostgreSQL documentation
7373
<productname>PostgreSQL</productname> backend server, or displaying
7474
the status of a running postmaster. Although the postmaster can be
7575
started manually, <application>pg_ctl</application> encapsulates
76-
tasks such as redirecting log output, properly detaching from the
77-
terminal and process group, and it provides convenient options for
76+
tasks such as redirecting log output and properly detaching from the
77+
terminal and process group. It also provides convenient options for
7878
controlled shutdown.
7979
</para>
8080

8181
<para>
8282
In <option>start</option> mode, a new postmaster is launched. The
83-
server is started in the background, the standard input attached to
83+
server is started in the background, and standard input is attached to
8484
<filename>/dev/null</filename>. The standard output and standard
85-
error are either appended to a log file, if the <option>-l</option>
86-
option is used, or are redirected to
87-
<application>pg_ctl</application>'s standard output (not standard
88-
error). If no log file is chosen, the standard output of
89-
<application>pg_ctl</application> should be redirected to a file or
90-
piped to another process, for example a log rotating program,
91-
otherwise the postmaster will write its output the the controlling
85+
error are either appended to a log file (if the <option>-l</option>
86+
option is used), or redirected to <application>pg_ctl</application>'s
87+
standard output (not standard error). If no log file is chosen, the
88+
standard output of <application>pg_ctl</application> should be redirected
89+
to a file or piped to another process, for example a log rotating program,
90+
otherwise the postmaster will write its output to the controlling
9291
terminal (from the background) and will not leave the shell's
9392
process group.
9493
</para>
@@ -102,8 +101,8 @@ PostgreSQL documentation
102101
not wait for clients to disconnect. All active transactions are
103102
rolled back and clients are forcibly disconnected, then the
104103
database is shut down. <quote>Immediate</quote> mode will abort
105-
all server processes without clean shutdown. This will lead to a recovery
106-
run on restart.
104+
all server processes without a clean shutdown. This will lead to
105+
a recovery run on restart.
107106
</para>
108107

109108
<para>
@@ -121,9 +120,9 @@ PostgreSQL documentation
121120
</para>
122121

123122
<para>
124-
<option>status</option> mode checks whether a postmaster is running
125-
and if so displays the <acronym>PID</acronym> and the command line
126-
options that were used to invoke it.
123+
<option>status</option> mode checks whether a postmaster is running.
124+
If it is, the <acronym>PID</acronym> and the command line
125+
options that were used to invoke it are displayed.
127126
</para>
128127
</refsect1>
129128

@@ -188,7 +187,7 @@ PostgreSQL documentation
188187
<para>
189188
Specifies the location of the <filename>postmaster</filename>
190189
executable. By default the postmaster is taken from the same
191-
directory as <command>pg_ctl</>, or failing that, the hard-wired
190+
directory as <command>pg_ctl</command>, or failing that, the hard-wired
192191
installation directory. It is not necessary to use this
193192
option unless you are doing something unusual and get errors
194193
that the postmaster was not found.
@@ -210,7 +209,16 @@ PostgreSQL documentation
210209
<listitem>
211210
<para>
212211
Wait for the start or shutdown to complete. Times out after
213-
60 seconds. This is the default for shutdowns.
212+
60 seconds. This is the default for shutdowns. A successful
213+
shutdown is indicated by removal of the <acronym>PID</scronym>
214+
file. For starting up, a successful <command>psql -l</command>
215+
indicates success. <command>pg_ctl</command> will attempt to
216+
use the proper port for psql. If the environment variable
217+
PGPORT exists, that is used. Otherwise, it will see if a port
218+
has been set in the <filename>postgresql.conf</filename> file.
219+
If neither of those is used, it will use the default port that
220+
<productname>PostgreSQL</productname> was compiled with
221+
(5432 by default).
214222
</para>
215223
</listitem>
216224
</varlistentry>
@@ -238,7 +246,17 @@ PostgreSQL documentation
238246

239247
<listitem>
240248
<para>
241-
Default data direction location
249+
Default data directory location.
250+
</para>
251+
</listitem>
252+
</varlistentry>
253+
254+
<varlistentry>
255+
<term><envar>PGPORT</envar></term>
256+
257+
<listitem>
258+
<para>
259+
Default port for <xref linkend="app-psql"> (used by the -w option).
242260
</para>
243261
</listitem>
244262
</varlistentry>
@@ -253,12 +271,58 @@ PostgreSQL documentation
253271
<refsect1>
254272
<title>Files</title>
255273

256-
<para>
257-
If the file <filename>postmaster.opts.default</filename> exists in
258-
the data directory, the contents of the file will be passed as
259-
options to the <application>postmaster</application>, unless
260-
overridden by the <option>-o</option> option.
261-
</para>
274+
<variablelist>
275+
<varlistentry>
276+
<term><filename>postmaster.pid</filename></term>
277+
278+
<listitem>
279+
<para>The existence of this file in the data directory is used to help
280+
<application>pg_ctl</application> determine if the server is
281+
currently running or not.
282+
</para>
283+
</listitem>
284+
</varlistentry>
285+
286+
<varlistentry>
287+
<term><filename>postmaster.opts.default</filename></term>
288+
289+
<listitem>
290+
<para>If this file exists in the data directory,
291+
<application>pg_ctl</application> (in <option>start</option> mode)
292+
will pass the contents of the file as options to the
293+
<application>postmaster</application>, unless overridden
294+
by the <option>-o</option> option.
295+
</para>
296+
</listitem>
297+
</varlistentry>
298+
299+
<varlistentry>
300+
<term><filename>postmaster.opts</filename></term>
301+
302+
<listitem>
303+
<para>If this file exists in the data directory,
304+
<application>pg_ctl</application> (in <option>restart</option> mode)
305+
will pass the contents of the file as options to the
306+
<application>postmaster</application>, unless overridden
307+
by the <option>-o</option> option. The contents of this file
308+
are also displayed in <option>status</option> mode.
309+
</para>
310+
</listitem>
311+
</varlistentry>
312+
313+
<varlistentry>
314+
<term><filename>postgresql.conf</filename></term>
315+
316+
<listitem>
317+
<para>This file, located in the data directory, is parsed to
318+
find the proper port to send to the
319+
<application>psql</application> when the <option>-w</option>
320+
is given in <option>start</option> mode.
321+
</para>
322+
</listitem>
323+
</varlistentry>
324+
325+
</variablelist>
262326
</refsect1>
263327

264328

@@ -268,7 +332,7 @@ PostgreSQL documentation
268332
<para>
269333
Waiting for complete start is not a well-defined operation and may
270334
fail if access control is set up so that a local client cannot
271-
connect without manual interaction. It should be avoided.
335+
connect without manual interaction (e.g. password authentication).
272336
</para>
273337
</refsect1>
274338

src/bin/pg_ctl/Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#
55
# Copyright (c) 1999, PostgreSQL Global Development Group
66
#
7-
# $Header: /cvsroot/pgsql/src/bin/pg_ctl/Makefile,v 1.10 2000/11/25 17:17:30 petere Exp $
7+
# $Header: /cvsroot/pgsql/src/bin/pg_ctl/Makefile,v 1.11 2003/03/20 05:00:14 momjian Exp $
88
#
99
#-------------------------------------------------------------------------
1010

@@ -17,6 +17,7 @@ all: pg_ctl
1717
pg_ctl: pg_ctl.sh
1818
sed -e 's/@VERSION@/$(VERSION)/g' \
1919
-e 's,@bindir@,$(bindir),g' \
20+
-e 's,@DEF_PGPORT@,$(DEF_PGPORT),g' \
2021
$< >$@
2122
chmod a+x $@
2223

src/bin/pg_ctl/pg_ctl.sh

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
#
99
#
1010
# IDENTIFICATION
11-
# $Header: /cvsroot/pgsql/src/bin/pg_ctl/Attic/pg_ctl.sh,v 1.31 2003/02/14 22:18:25 momjian Exp $
11+
# $Header: /cvsroot/pgsql/src/bin/pg_ctl/Attic/pg_ctl.sh,v 1.32 2003/03/20 05:00:14 momjian Exp $
1212
#
1313
#-------------------------------------------------------------------------
1414

@@ -60,6 +60,7 @@ Try '$CMDNAME --help' for more information."
6060
# Placed here during build
6161
bindir='@bindir@'
6262
VERSION='@VERSION@'
63+
DEF_PGPORT='@DEF_PGPORT@'
6364

6465
# protect the log file
6566
umask 077
@@ -240,6 +241,7 @@ fi
240241
DEFPOSTOPTS=$PGDATA/postmaster.opts.default
241242
POSTOPTSFILE=$PGDATA/postmaster.opts
242243
PIDFILE=$PGDATA/postmaster.pid
244+
CONFFILE=$PGDATA/postgresql.conf
243245

244246
if [ "$op" = "status" ];then
245247
if [ -f "$PIDFILE" ];then
@@ -356,25 +358,33 @@ if [ "$op" = "start" -o "$op" = "restart" ];then
356358
fi
357359
fi
358360

359-
# wait for postmaster to start
360-
if [ "$wait" = yes ];then
361-
cnt=0
362-
$silence_echo $ECHO_N "waiting for postmaster to start..."$ECHO_C
363-
while :
364-
do
365361
# FIXME: This is horribly misconceived.
366362
# 1) If password authentication is set up, the connection will fail.
367363
# 2) If a virtual host is set up, the connection may fail.
368364
# 3) If network traffic filters are set up tight enough, the connection
369365
# may fail.
370366
# 4) When no Unix domain sockets are available, the connection will
371367
# fail. (Using TCP/IP by default ain't better.)
372-
# 5) When a different port is configured, the connection will fail
373-
# or go to the wrong server.
374-
# 6) If the dynamic loader is not set up correctly (for this user/at
368+
# 5) If the dynamic loader is not set up correctly (for this user/at
375369
# this time), psql will fail (to find libpq).
376-
# 7) If psql is misconfigured, this may fail.
377-
if "$PGPATH/psql" -l >/dev/null 2>&1
370+
# 6) If psql is misconfigured, this may fail.
371+
372+
# Attempt to use the right port
373+
# Use PGPORT if set, otherwise look in the configuration file
374+
if [ -z $PGPORT ];then
375+
PGPORT=`sed -ne 's/^[ ]*port[^=]*=[ ]\+\([0-9]\+\).*/\1/p' $CONFFILE 2>/dev/null`
376+
if [ -z $PGPORT ];then
377+
PGPORT=$DEF_PGPORT
378+
fi
379+
fi
380+
381+
# wait for postmaster to start
382+
if [ "$wait" = yes ];then
383+
cnt=0
384+
$silence_echo $ECHO_N "waiting for postmaster to start..."$ECHO_C
385+
while :
386+
do
387+
if "$PGPATH/psql" -p $PGPORT -l >/dev/null 2>&1
378388
then
379389
break;
380390
else

0 commit comments

Comments
 (0)