Обсуждение: pg_ctl -w port detection

Поиск
Список
Период
Сортировка

pg_ctl -w port detection

От
"Greg Sabino Mullane"
Дата:
-----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-----



Re: pg_ctl -w port detection

От
Tom Lane
Дата:
"Greg Sabino Mullane" <greg@turnstep.com> writes:
> 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).

Seems reasonable ... but you forgot to update the pg_ctl manual page.

            regards, tom lane

Re: pg_ctl -w port detection

От
greg@turnstep.com
Дата:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1


> Seems reasonable ... but you forgot to update the pg_ctl manual page.

I looked that over, but could not really see where any addition was
needed, as the -w flag is given a fairly cursory mention. Suggestions
welcome of course. :)

- --
Greg Sabino Mullane  greg@turnstep.com
PGP Key: 0x14964AC8 200302221140

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

iD8DBQE+VjZOvJuQZxSWSsgRAonAAKCsFBdeUOuZm090MLgCe3ettvaQ3ACfTfas
BLK67kMf9oA40UnIDoCp9OY=
=yDF+
-----END PGP SIGNATURE-----



Re: pg_ctl -w port detection

От
Tom Lane
Дата:
greg@turnstep.com writes:
>> Seems reasonable ... but you forgot to update the pg_ctl manual page.

> I looked that over, but could not really see where any addition was
> needed, as the -w flag is given a fairly cursory mention. Suggestions
> welcome of course. :)

The dependency on PGPORT should be mentioned under Environment,
for one thing.  But really the problem here is that there's no
discussion of pg_ctl's use of psql for watching postmaster startup,
other than the *very* cursory mention under Notes.  That should be
expanded, IMHO, because it's the source of most problems with pg_ctl.

            regards, tom lane