pg_ctl -w port detection

From: "Greg Sabino Mullane" <greg(at)turnstep(dot)com>
To: pgsql-patches(at)postgresql(dot)org
Subject: pg_ctl -w port detection
Date: 2003-02-22 14:57:47
Message-ID: 221fa5a9966a3c7c0f3310fa9e0447dc@biglumber.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-patches


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
NotDashEscaped: You need GnuPG to verify this message

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(at)turnstep(dot)com
PGP Key: 0x14964AC8 200302220955

Index: pg_ctl.sh
===================================================================
RCS file: /projects/cvsroot/pgsql-server/src/bin/pg_ctl/pg_ctl.sh,v
retrieving revision 1.31
diff -c -r1.31 pg_ctl.sh
*** pg_ctl.sh 2003/02/14 22:18:25 1.31
--- pg_ctl.sh 2003/02/22 14:47:09
***************
*** 60,65 ****
--- 60,66 ----
# Placed here during build
bindir='@bindir@'
VERSION='@VERSION@'
+ DEF_PGPORT='@DEF_PGPORT@'

# protect the log file
umask 077
***************
*** 240,245 ****
--- 241,247 ----
DEFPOSTOPTS=$PGDATA/postmaster.opts.default
POSTOPTSFILE=$PGDATA/postmaster.opts
PIDFILE=$PGDATA/postmaster.pid
+ CONFFILE=$PGDATA/postgresql.conf

if [ "$op" = "status" ];then
if [ -f "$PIDFILE" ];then
***************
*** 356,367 ****
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.
# 1) If password authentication is set up, the connection will fail.
# 2) If a virtual host is set up, the connection may fail.
--- 358,363 ----
***************
*** 369,380 ****
# may fail.
# 4) When no Unix domain sockets are available, the connection will
# fail. (Using TCP/IP by default ain't better.)
! # 5) When a different port is configured, the connection will fail
! # 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).
! # 7) If psql is misconfigured, this may fail.
! if "$PGPATH/psql" -l >/dev/null 2>&1
then
break;
else
--- 365,390 ----
# may fail.
# 4) When no Unix domain sockets are available, the connection will
# fail. (Using TCP/IP by default ain't better.)
! # 5) If the dynamic loader is not set up correctly (for this user/at
# this time), psql will fail (to find libpq).
! # 6) If psql is misconfigured, this may fail.
!
! # 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
break;
else
Index: Makefile
===================================================================
RCS file: /projects/cvsroot/pgsql-server/src/bin/pg_ctl/Makefile,v
retrieving revision 1.10
diff -c -r1.10 Makefile
*** Makefile 2000/11/25 17:17:30 1.10
--- Makefile 2003/02/22 14:47:40
***************
*** 17,22 ****
--- 17,23 ----
pg_ctl: pg_ctl.sh
sed -e 's/@VERSION@/$(VERSION)/g' \
-e 's,@bindir@,$(bindir),g' \
+ -e 's,@DEF_PGPORT@,$(DEF_PGPORT),g' \
$< >$@
chmod a+x $@

-----BEGIN PGP SIGNATURE-----
Comment: http://www.turnstep.com/pgp.html

iD8DBQE+Vh0dvJuQZxSWSsgRAiZ3AKDCARsjinFLSIUEfH6Ueg0iH4T3DQCgyWmS
utFY02zy9JBW6HB4gdsvgn8=
=g1ZQ
-----END PGP SIGNATURE-----

Responses

Browse pgsql-patches by date

  From Date Subject
Next Message Jeroen T. Vermeulen 2003-02-22 16:07:45 Re: psql patch
Previous Message Tom Lane 2003-02-22 04:41:36 Re: implement query_start for pg_stat_activity