pg_ctl -w port detection - Mailing list pgsql-patches

From Greg Sabino Mullane
Subject pg_ctl -w port detection
Date
Msg-id 221fa5a9966a3c7c0f3310fa9e0447dc@biglumber.com
Whole thread Raw
Responses Re: pg_ctl -w port detection  (Tom Lane <tgl@sss.pgh.pa.us>)
List 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@turnstep.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-----



pgsql-patches by date:

Previous
From: Tom Lane
Date:
Subject: Re: implement query_start for pg_stat_activity
Next
From: Tom Lane
Date:
Subject: Re: pg_ctl -w port detection