Fwd: Bug#358546: failure of pg_ctl start -w -D

Started by Martin Pittabout 20 years ago3 messagesbugs
Jump to latest
#1Martin Pitt
mpitt@debian.org

Hi PostgreSQL developers,

the bug report below was recently sent to Debian. The details and my
reply are at http://bugs.debian.org/358546, the executive summary is:
pg_ctl's -w option does not honour postgresql.conf's
unix_socket_directory configuration (and neither $PGHOST).

Thanks,

Martin

----- Forwarded message from Stephen Gildea <gildea@stop.mail-abuse.org> -----

Subject: Bug#358546: failure of pg_ctl start -w -D
Reply-To: Stephen Gildea <gildea@stop.mail-abuse.org>,
358546@bugs.debian.org
From: Stephen Gildea <gildea@stop.mail-abuse.org>
To: submit@bugs.debian.org
Date: Wed, 22 Mar 2006 22:39:27 -0500
X-Spam-Status: No, score=1.3 required=4.0 tests=BAYES_50,DATE_IN_FUTURE_06_12
autolearn=no version=3.0.3

Package: postgresql-7.4
Version: 7.4.12-2
Tags: patch

When starting the PostgreSQL server (with "pg_ctl start") with a
specific directory (the -D flag), the "wait" code (triggered with the -w
option) fails to use the directory to find the Unix socket, and so it
fails to connect to the newly-started server.

To repeat, create a new database and start a server on it:

/usr/lib/postgresql/bin/initdb -D /some/directory
Edit /some/directory/postgresql.conf to define unix_socket_directory.
(It may be a separate bug that this step is necessary.)
/usr/lib/postgresql/bin/pg_ctl start -w -D /some/directory -l /some/directory/postgres.log
Note the "failed" error message, even though the server did start.

The following simple patch passes the Unix socket directory to psql for
the wait check.

In PostgreSQL 8, the pg_ctl shell script has been replaced by a C
program. I haven't tested it, but from looking at the code in pg_ctl.c,
I suspect the same bug is present. Running "start -w" calls
test_postmaster_connection(). As with the buggy script, that routine
sets only the port and fails to set the host/directory as well.

< Stephen

--- postgresql-7.4.12/src/bin/pg_ctl/pg_ctl.sh	2004-10-21 20:24:27.000000000 -0400
+++ src/bin/pg_ctl/pg_ctl.sh	2006-03-20 13:31:23.000000000 -0500
@@ -387,20 +387,23 @@
     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
+    if [ -z "$PGHOST" ];then
+        PGHOST=`sed -ne "s/^[ 	]*unix_socket_directory[^=]*=[ 	]\+'\([^'].*\)'/\1/p" "$CONFFILE" 2>/dev/null`
+    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
+	    if "$PGPATH/psql" -p $PGPORT -h "$PGHOST" -l >/dev/null 2>&1
 	    then
 		break;
 	    else
 		$silence_echo $ECHO_N "."$ECHO_C
 		cnt=`expr $cnt + 1`
 		if [ "$cnt" -gt "$wait_seconds" ];then

----- End forwarded message -----

--
Martin Pitt http://www.piware.de
Ubuntu Developer http://www.ubuntu.com
Debian Developer http://www.debian.org

In a world without walls and fences, who needs Windows and Gates?

#2Martin Pitt
martin@piware.de
In reply to: Martin Pitt (#1)

Hi PostgreSQL developers,

the bug report below was recently sent to Debian. The details and my
reply are at http://bugs.debian.org/358546, the executive summary is:
pg_ctl's -w option does not honour postgresql.conf's
unix_socket_directory configuration (and neither $PGHOST).

Thanks,

Martin
----- Forwarded message from Stephen Gildea <gildea@stop.mail-abuse.org> -----

Subject: Bug#358546: failure of pg_ctl start -w -D
Reply-To: Stephen Gildea <gildea@stop.mail-abuse.org>,
358546@bugs.debian.org
From: Stephen Gildea <gildea@stop.mail-abuse.org>
To: submit@bugs.debian.org
Date: Wed, 22 Mar 2006 22:39:27 -0500
X-Spam-Status: No, score=1.3 required=4.0 tests=BAYES_50,DATE_IN_FUTURE_06_12
autolearn=no version=3.0.3

Package: postgresql-7.4
Version: 7.4.12-2
Tags: patch

When starting the PostgreSQL server (with "pg_ctl start") with a
specific directory (the -D flag), the "wait" code (triggered with the -w
option) fails to use the directory to find the Unix socket, and so it
fails to connect to the newly-started server.

To repeat, create a new database and start a server on it:

/usr/lib/postgresql/bin/initdb -D /some/directory
Edit /some/directory/postgresql.conf to define unix_socket_directory.
(It may be a separate bug that this step is necessary.)
/usr/lib/postgresql/bin/pg_ctl start -w -D /some/directory -l /some/directory/postgres.log
Note the "failed" error message, even though the server did start.

The following simple patch passes the Unix socket directory to psql for
the wait check.

In PostgreSQL 8, the pg_ctl shell script has been replaced by a C
program. I haven't tested it, but from looking at the code in pg_ctl.c,
I suspect the same bug is present. Running "start -w" calls
test_postmaster_connection(). As with the buggy script, that routine
sets only the port and fails to set the host/directory as well.

< Stephen

--- postgresql-7.4.12/src/bin/pg_ctl/pg_ctl.sh	2004-10-21 20:24:27.000000000 -0400
+++ src/bin/pg_ctl/pg_ctl.sh	2006-03-20 13:31:23.000000000 -0500
@@ -387,20 +387,23 @@
     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
+    if [ -z "$PGHOST" ];then
+        PGHOST=`sed -ne "s/^[ 	]*unix_socket_directory[^=]*=[ 	]\+'\([^'].*\)'/\1/p" "$CONFFILE" 2>/dev/null`
+    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
+	    if "$PGPATH/psql" -p $PGPORT -h "$PGHOST" -l >/dev/null 2>&1
 	    then
 		break;
 	    else
 		$silence_echo $ECHO_N "."$ECHO_C
 		cnt=`expr $cnt + 1`
 		if [ "$cnt" -gt "$wait_seconds" ];then

----- End forwarded message -----

--
Martin Pitt http://www.piware.de
Ubuntu Developer http://www.ubuntu.com
Debian Developer http://www.debian.org

In a world without walls and fences, who needs Windows and Gates?

#3Tom Lane
tgl@sss.pgh.pa.us
In reply to: Martin Pitt (#2)
Re: Fwd: Bug#358546: failure of pg_ctl start -w -D

Martin Pitt <martin@piware.de> writes:

the bug report below was recently sent to Debian. The details and my
reply are at http://bugs.debian.org/358546, the executive summary is:
pg_ctl's -w option does not honour postgresql.conf's
unix_socket_directory configuration (and neither $PGHOST).

The proposed patch is just a kluge. We already have a TODO item about
the right way to fix it, which is to teach pg_ctl how to read the
postgresql.conf file for itself --- this is needed for other possible
settings such as data_directory, not only unix_socket_directory.

regards, tom lane