mirror of
https://github.com/postgres/postgres.git
synced 2025-05-31 03:21:24 +03:00
(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
This commit is contained in:
parent
3c28f9c144
commit
54ca7a7b13
@ -1,5 +1,5 @@
|
|||||||
<!--
|
<!--
|
||||||
$Header: /cvsroot/pgsql/doc/src/sgml/ref/pg_ctl-ref.sgml,v 1.18 2003/01/19 00:13:30 momjian Exp $
|
$Header: /cvsroot/pgsql/doc/src/sgml/ref/pg_ctl-ref.sgml,v 1.19 2003/03/20 05:00:14 momjian Exp $
|
||||||
PostgreSQL documentation
|
PostgreSQL documentation
|
||||||
-->
|
-->
|
||||||
|
|
||||||
@ -73,22 +73,21 @@ PostgreSQL documentation
|
|||||||
<productname>PostgreSQL</productname> backend server, or displaying
|
<productname>PostgreSQL</productname> backend server, or displaying
|
||||||
the status of a running postmaster. Although the postmaster can be
|
the status of a running postmaster. Although the postmaster can be
|
||||||
started manually, <application>pg_ctl</application> encapsulates
|
started manually, <application>pg_ctl</application> encapsulates
|
||||||
tasks such as redirecting log output, properly detaching from the
|
tasks such as redirecting log output and properly detaching from the
|
||||||
terminal and process group, and it provides convenient options for
|
terminal and process group. It also provides convenient options for
|
||||||
controlled shutdown.
|
controlled shutdown.
|
||||||
</para>
|
</para>
|
||||||
|
|
||||||
<para>
|
<para>
|
||||||
In <option>start</option> mode, a new postmaster is launched. The
|
In <option>start</option> mode, a new postmaster is launched. The
|
||||||
server is started in the background, the standard input attached to
|
server is started in the background, and standard input is attached to
|
||||||
<filename>/dev/null</filename>. The standard output and standard
|
<filename>/dev/null</filename>. The standard output and standard
|
||||||
error are either appended to a log file, if the <option>-l</option>
|
error are either appended to a log file (if the <option>-l</option>
|
||||||
option is used, or are redirected to
|
option is used), or redirected to <application>pg_ctl</application>'s
|
||||||
<application>pg_ctl</application>'s standard output (not standard
|
standard output (not standard error). If no log file is chosen, the
|
||||||
error). If no log file is chosen, the standard output of
|
standard output of <application>pg_ctl</application> should be redirected
|
||||||
<application>pg_ctl</application> should be redirected to a file or
|
to a file or piped to another process, for example a log rotating program,
|
||||||
piped to another process, for example a log rotating program,
|
otherwise the postmaster will write its output to the controlling
|
||||||
otherwise the postmaster will write its output the the controlling
|
|
||||||
terminal (from the background) and will not leave the shell's
|
terminal (from the background) and will not leave the shell's
|
||||||
process group.
|
process group.
|
||||||
</para>
|
</para>
|
||||||
@ -102,8 +101,8 @@ PostgreSQL documentation
|
|||||||
not wait for clients to disconnect. All active transactions are
|
not wait for clients to disconnect. All active transactions are
|
||||||
rolled back and clients are forcibly disconnected, then the
|
rolled back and clients are forcibly disconnected, then the
|
||||||
database is shut down. <quote>Immediate</quote> mode will abort
|
database is shut down. <quote>Immediate</quote> mode will abort
|
||||||
all server processes without clean shutdown. This will lead to a recovery
|
all server processes without a clean shutdown. This will lead to
|
||||||
run on restart.
|
a recovery run on restart.
|
||||||
</para>
|
</para>
|
||||||
|
|
||||||
<para>
|
<para>
|
||||||
@ -121,9 +120,9 @@ PostgreSQL documentation
|
|||||||
</para>
|
</para>
|
||||||
|
|
||||||
<para>
|
<para>
|
||||||
<option>status</option> mode checks whether a postmaster is running
|
<option>status</option> mode checks whether a postmaster is running.
|
||||||
and if so displays the <acronym>PID</acronym> and the command line
|
If it is, the <acronym>PID</acronym> and the command line
|
||||||
options that were used to invoke it.
|
options that were used to invoke it are displayed.
|
||||||
</para>
|
</para>
|
||||||
</refsect1>
|
</refsect1>
|
||||||
|
|
||||||
@ -188,7 +187,7 @@ PostgreSQL documentation
|
|||||||
<para>
|
<para>
|
||||||
Specifies the location of the <filename>postmaster</filename>
|
Specifies the location of the <filename>postmaster</filename>
|
||||||
executable. By default the postmaster is taken from the same
|
executable. By default the postmaster is taken from the same
|
||||||
directory as <command>pg_ctl</>, or failing that, the hard-wired
|
directory as <command>pg_ctl</command>, or failing that, the hard-wired
|
||||||
installation directory. It is not necessary to use this
|
installation directory. It is not necessary to use this
|
||||||
option unless you are doing something unusual and get errors
|
option unless you are doing something unusual and get errors
|
||||||
that the postmaster was not found.
|
that the postmaster was not found.
|
||||||
@ -210,7 +209,16 @@ PostgreSQL documentation
|
|||||||
<listitem>
|
<listitem>
|
||||||
<para>
|
<para>
|
||||||
Wait for the start or shutdown to complete. Times out after
|
Wait for the start or shutdown to complete. Times out after
|
||||||
60 seconds. This is the default for shutdowns.
|
60 seconds. This is the default for shutdowns. A successful
|
||||||
|
shutdown is indicated by removal of the <acronym>PID</scronym>
|
||||||
|
file. For starting up, a successful <command>psql -l</command>
|
||||||
|
indicates success. <command>pg_ctl</command> will attempt to
|
||||||
|
use the proper port for psql. If the environment variable
|
||||||
|
PGPORT exists, that is used. Otherwise, it will see if a port
|
||||||
|
has been set in the <filename>postgresql.conf</filename> file.
|
||||||
|
If neither of those is used, it will use the default port that
|
||||||
|
<productname>PostgreSQL</productname> was compiled with
|
||||||
|
(5432 by default).
|
||||||
</para>
|
</para>
|
||||||
</listitem>
|
</listitem>
|
||||||
</varlistentry>
|
</varlistentry>
|
||||||
@ -238,7 +246,17 @@ PostgreSQL documentation
|
|||||||
|
|
||||||
<listitem>
|
<listitem>
|
||||||
<para>
|
<para>
|
||||||
Default data direction location
|
Default data directory location.
|
||||||
|
</para>
|
||||||
|
</listitem>
|
||||||
|
</varlistentry>
|
||||||
|
|
||||||
|
<varlistentry>
|
||||||
|
<term><envar>PGPORT</envar></term>
|
||||||
|
|
||||||
|
<listitem>
|
||||||
|
<para>
|
||||||
|
Default port for <xref linkend="app-psql"> (used by the -w option).
|
||||||
</para>
|
</para>
|
||||||
</listitem>
|
</listitem>
|
||||||
</varlistentry>
|
</varlistentry>
|
||||||
@ -253,12 +271,58 @@ PostgreSQL documentation
|
|||||||
<refsect1>
|
<refsect1>
|
||||||
<title>Files</title>
|
<title>Files</title>
|
||||||
|
|
||||||
<para>
|
<variablelist>
|
||||||
If the file <filename>postmaster.opts.default</filename> exists in
|
<varlistentry>
|
||||||
the data directory, the contents of the file will be passed as
|
<term><filename>postmaster.pid</filename></term>
|
||||||
options to the <application>postmaster</application>, unless
|
|
||||||
overridden by the <option>-o</option> option.
|
<listitem>
|
||||||
</para>
|
<para>The existence of this file in the data directory is used to help
|
||||||
|
<application>pg_ctl</application> determine if the server is
|
||||||
|
currently running or not.
|
||||||
|
</para>
|
||||||
|
</listitem>
|
||||||
|
</varlistentry>
|
||||||
|
|
||||||
|
<varlistentry>
|
||||||
|
<term><filename>postmaster.opts.default</filename></term>
|
||||||
|
|
||||||
|
<listitem>
|
||||||
|
<para>If this file exists in the data directory,
|
||||||
|
<application>pg_ctl</application> (in <option>start</option> mode)
|
||||||
|
will pass the contents of the file as options to the
|
||||||
|
<application>postmaster</application>, unless overridden
|
||||||
|
by the <option>-o</option> option.
|
||||||
|
</para>
|
||||||
|
</listitem>
|
||||||
|
</varlistentry>
|
||||||
|
|
||||||
|
<varlistentry>
|
||||||
|
<term><filename>postmaster.opts</filename></term>
|
||||||
|
|
||||||
|
<listitem>
|
||||||
|
<para>If this file exists in the data directory,
|
||||||
|
<application>pg_ctl</application> (in <option>restart</option> mode)
|
||||||
|
will pass the contents of the file as options to the
|
||||||
|
<application>postmaster</application>, unless overridden
|
||||||
|
by the <option>-o</option> option. The contents of this file
|
||||||
|
are also displayed in <option>status</option> mode.
|
||||||
|
</para>
|
||||||
|
</listitem>
|
||||||
|
</varlistentry>
|
||||||
|
|
||||||
|
<varlistentry>
|
||||||
|
<term><filename>postgresql.conf</filename></term>
|
||||||
|
|
||||||
|
<listitem>
|
||||||
|
<para>This file, located in the data directory, is parsed to
|
||||||
|
find the proper port to send to the
|
||||||
|
<application>psql</application> when the <option>-w</option>
|
||||||
|
is given in <option>start</option> mode.
|
||||||
|
</para>
|
||||||
|
</listitem>
|
||||||
|
</varlistentry>
|
||||||
|
|
||||||
|
</variablelist>
|
||||||
</refsect1>
|
</refsect1>
|
||||||
|
|
||||||
|
|
||||||
@ -268,7 +332,7 @@ PostgreSQL documentation
|
|||||||
<para>
|
<para>
|
||||||
Waiting for complete start is not a well-defined operation and may
|
Waiting for complete start is not a well-defined operation and may
|
||||||
fail if access control is set up so that a local client cannot
|
fail if access control is set up so that a local client cannot
|
||||||
connect without manual interaction. It should be avoided.
|
connect without manual interaction (e.g. password authentication).
|
||||||
</para>
|
</para>
|
||||||
</refsect1>
|
</refsect1>
|
||||||
|
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
#
|
#
|
||||||
# Copyright (c) 1999, PostgreSQL Global Development Group
|
# Copyright (c) 1999, PostgreSQL Global Development Group
|
||||||
#
|
#
|
||||||
# $Header: /cvsroot/pgsql/src/bin/pg_ctl/Makefile,v 1.10 2000/11/25 17:17:30 petere Exp $
|
# $Header: /cvsroot/pgsql/src/bin/pg_ctl/Makefile,v 1.11 2003/03/20 05:00:14 momjian Exp $
|
||||||
#
|
#
|
||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
|
|
||||||
@ -17,6 +17,7 @@ all: pg_ctl
|
|||||||
pg_ctl: pg_ctl.sh
|
pg_ctl: pg_ctl.sh
|
||||||
sed -e 's/@VERSION@/$(VERSION)/g' \
|
sed -e 's/@VERSION@/$(VERSION)/g' \
|
||||||
-e 's,@bindir@,$(bindir),g' \
|
-e 's,@bindir@,$(bindir),g' \
|
||||||
|
-e 's,@DEF_PGPORT@,$(DEF_PGPORT),g' \
|
||||||
$< >$@
|
$< >$@
|
||||||
chmod a+x $@
|
chmod a+x $@
|
||||||
|
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
#
|
#
|
||||||
#
|
#
|
||||||
# IDENTIFICATION
|
# IDENTIFICATION
|
||||||
# $Header: /cvsroot/pgsql/src/bin/pg_ctl/Attic/pg_ctl.sh,v 1.31 2003/02/14 22:18:25 momjian Exp $
|
# $Header: /cvsroot/pgsql/src/bin/pg_ctl/Attic/pg_ctl.sh,v 1.32 2003/03/20 05:00:14 momjian Exp $
|
||||||
#
|
#
|
||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
|
|
||||||
@ -60,6 +60,7 @@ Try '$CMDNAME --help' for more information."
|
|||||||
# Placed here during build
|
# Placed here during build
|
||||||
bindir='@bindir@'
|
bindir='@bindir@'
|
||||||
VERSION='@VERSION@'
|
VERSION='@VERSION@'
|
||||||
|
DEF_PGPORT='@DEF_PGPORT@'
|
||||||
|
|
||||||
# protect the log file
|
# protect the log file
|
||||||
umask 077
|
umask 077
|
||||||
@ -240,6 +241,7 @@ fi
|
|||||||
DEFPOSTOPTS=$PGDATA/postmaster.opts.default
|
DEFPOSTOPTS=$PGDATA/postmaster.opts.default
|
||||||
POSTOPTSFILE=$PGDATA/postmaster.opts
|
POSTOPTSFILE=$PGDATA/postmaster.opts
|
||||||
PIDFILE=$PGDATA/postmaster.pid
|
PIDFILE=$PGDATA/postmaster.pid
|
||||||
|
CONFFILE=$PGDATA/postgresql.conf
|
||||||
|
|
||||||
if [ "$op" = "status" ];then
|
if [ "$op" = "status" ];then
|
||||||
if [ -f "$PIDFILE" ];then
|
if [ -f "$PIDFILE" ];then
|
||||||
@ -356,12 +358,6 @@ if [ "$op" = "start" -o "$op" = "restart" ];then
|
|||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# wait for postmaster to start
|
|
||||||
if [ "$wait" = yes ];then
|
|
||||||
cnt=0
|
|
||||||
$silence_echo $ECHO_N "waiting for postmaster to start..."$ECHO_C
|
|
||||||
while :
|
|
||||||
do
|
|
||||||
# FIXME: This is horribly misconceived.
|
# FIXME: This is horribly misconceived.
|
||||||
# 1) If password authentication is set up, the connection will fail.
|
# 1) If password authentication is set up, the connection will fail.
|
||||||
# 2) If a virtual host is set up, the connection may fail.
|
# 2) If a virtual host is set up, the connection may fail.
|
||||||
@ -369,12 +365,26 @@ if [ "$op" = "start" -o "$op" = "restart" ];then
|
|||||||
# may fail.
|
# may fail.
|
||||||
# 4) When no Unix domain sockets are available, the connection will
|
# 4) When no Unix domain sockets are available, the connection will
|
||||||
# fail. (Using TCP/IP by default ain't better.)
|
# fail. (Using TCP/IP by default ain't better.)
|
||||||
# 5) When a different port is configured, the connection will fail
|
# 5) If the dynamic loader is not set up correctly (for this user/at
|
||||||
# or go to the wrong server.
|
|
||||||
# 6) If the dynamic loader is not set up correctly (for this user/at
|
|
||||||
# this time), psql will fail (to find libpq).
|
# this time), psql will fail (to find libpq).
|
||||||
# 7) If psql is misconfigured, this may fail.
|
# 6) If psql is misconfigured, this may fail.
|
||||||
if "$PGPATH/psql" -l >/dev/null 2>&1
|
|
||||||
|
# Attempt to use the right port
|
||||||
|
# Use PGPORT if set, otherwise look in the configuration file
|
||||||
|
if [ -z $PGPORT ];then
|
||||||
|
PGPORT=`sed -ne 's/^[ ]*port[^=]*=[ ]\+\([0-9]\+\).*/\1/p' $CONFFILE 2>/dev/null`
|
||||||
|
if [ -z $PGPORT ];then
|
||||||
|
PGPORT=$DEF_PGPORT
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
# wait for postmaster to start
|
||||||
|
if [ "$wait" = yes ];then
|
||||||
|
cnt=0
|
||||||
|
$silence_echo $ECHO_N "waiting for postmaster to start..."$ECHO_C
|
||||||
|
while :
|
||||||
|
do
|
||||||
|
if "$PGPATH/psql" -p $PGPORT -l >/dev/null 2>&1
|
||||||
then
|
then
|
||||||
break;
|
break;
|
||||||
else
|
else
|
||||||
|
Loading…
x
Reference in New Issue
Block a user