Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 228639 - dev-db/postgresql-server-8.3.3 init script fails when local (unix socket) connections are disabled
Summary: dev-db/postgresql-server-8.3.3 init script fails when local (unix socket) con...
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: [OLD] Server (show other bugs)
Hardware: All Linux
: High major (vote)
Assignee: PgSQL Bugs
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-06-20 22:22 UTC by wyvern5
Modified: 2008-09-28 22:52 UTC (History)
2 users (show)

See Also:
Package list:
Runtime testing required: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description wyvern5 2008-06-20 22:22:26 UTC
When starting up the server, pg_ctl -w is used, which seems ok except for the fact that pg_ctl -w tries to make a local unix socket connection to verify that the server is up. This fails miserably when you disable local unix socket access in pg_hba (as is quite commonly done, since local unix sockets are useless for a networked db server). 

The fix is simply to remove -w from the pg_ctl line in the init script. The server starts and stops normally.

The init script for dev-db/postgresql-8.3.1 used start-stop-daemon rather than pg_ctl, so it did not encounter this bug. Regardless, pg_ctl is the proper tool to use; it just shouldn't have the -w. :)

Reproducible: Always

Steps to Reproduce:
1. Disable 'local' access in pg_hba.conf
2. Try to start postgresql server 8.3
3. Watch it fail as it waits and waits and waits for the server to start. The server ACTUALLY HAS STARTED but because it's refusing unix socket connections, pg_ctl -w never thinks it's started.

Actual Results:  
"/etc/init.d/postgresql-8.3 start" just waits forever for the server to start

Expected Results:  
The init script should return.
Comment 1 Tiziano Müller (RETIRED) gentoo-dev 2008-06-21 07:00:33 UTC
hmm, that's really bad because I can't remove "-w" since it would break a lot of other things (scenario: server starts but isn't ready yet, service depending on postgresql is coming up but can't make a connection, fail).
Comment 2 wyvern5 2008-06-21 19:46:44 UTC
(In reply to comment #1)
> hmm, that's really bad because I can't remove "-w" since it would break a lot
> of other things (scenario: server starts but isn't ready yet, service depending
> on postgresql is coming up but can't make a connection, fail).
> 

Yeah, I can see how that would be a problem. How about adding an optional var in the conf.d file to remove -w and add a configurable sleep time so that it isn't totally broken for people who remove unix socket access? Or, at the very least, add some info to the ebuild to tell people about the problem.
Comment 3 Caleb Tennis (RETIRED) gentoo-dev 2008-09-24 21:34:53 UTC
This also fails if your server is doing replication, and you try to start the replica.  I agree with the making "-w" part of an optional config.

Also, why not use pg_ctl for stopping the server as well?

Here's my proposed patch diff:

--- postgresql-8.3	2008-09-24 13:00:51.000000000 -0700
+++ postgresql-8.3.new	2008-09-24 13:58:34.000000000 -0700
@@ -34,7 +34,7 @@
	local retval

	su -l ${PGUSER} \
-		-c "env PGDATA=\"${PGDATA}\" /usr/lib/postgresql-8.3/bin/pg_ctl start -w -o '--silent-mode=true ${PGOPTS}'"
+		-c "env PGDATA=\"${PGDATA}\" /usr/lib/postgresql-8.3/bin/pg_ctl start ${WAIT_FOR_START} -o '--silent-mode=true ${PGOPTS}'"
	retval=$?
	[ $retval -ne 0 ] && eend $retval && return $retval

@@ -58,16 +58,16 @@

	local retval

-	start-stop-daemon --stop --pidfile "${PGDATA}/postmaster.pid" \
-		--retry -TERM/${WAIT_FOR_DISCONNECT}
+  su -l ${PGUSER} \
+    -c "env PGDATA=\"${PGDATA}\" /usr/lib/postgresql-8.3/bin/pg_ctl stop -t ${WAIT_FOR_DISCONNECT} -m smart"
	retval=$?
	[ $retval -eq 0 ] && eend $retval && return $retval

	ewarn "Some clients did not disconnect within ${WAIT_FOR_DISCONNECT} seconds."
	ewarn "Going to shutdown the server anyway."

-	start-stop-daemon --stop --pidfile "${PGDATA}/postmaster.pid" \
-		--retry -INT/${WAIT_FOR_CLEANUP}
+  su -l ${PGUSER} \
+    -c "env PGDATA=\"${PGDATA}\" /usr/lib/postgresql-8.3/bin/pg_ctl stop -m fast"
	retval=$?
	[ $retval -eq 0 ] && eend $retval && return $retval

@@ -80,8 +80,8 @@
	ewarn "Shutting down the server gracefully failed."
	ewarn "Forcing it to shutdown which leads to a recover-run on next startup."

-	start-stop-daemon --stop --pidfile "${PGDATA}/postmaster.pid" \
-		--retry -QUIT/${WAIT_FOR_QUIT}
+  su -l ${PGUSER} \
+    -c "env PGDATA=\"${PGDATA}\" /usr/lib/postgresql-8.3/bin/pg_ctl stop -m immediate"
	retval=$?
	[ $retval -eq 0 ] && eend $retval && return $retval

@@ -91,6 +91,7 @@

reload() {
	ebegin "Reloading PostgreSQL configuration"
-	start-stop-daemon --stop --pidfile "${PGDATA}/postmaster.pid" --signal HUP --oknodo
+  su -l ${PGUSER} \
+    -c "env PGDATA=\"${PGDATA}\" /usr/lib/postgresql-8.3/bin/pg_ctl reload"
	eend $?
}
Comment 4 Caleb Tennis (RETIRED) gentoo-dev 2008-09-24 22:00:48 UTC
Note this also requires a slight change to the conf file:

--- etc/conf.d/postgresql-8.3	2008-09-24 14:51:06.000000000 -0700
+++ etc/conf.d/postgresql-8.3-new	2008-09-24 14:54:32.000000000 -0700
@@ -40,6 +40,10 @@
# Set to 0 to deactivate it
WAIT_FOR_QUIT=60

+# Comment this out if you don't want to wait for the server to 
+# # startup before continuing...for example if this server is a 
+# # PITR log shipping based replication standby
+WAIT_FOR_START="-w"

# If you have to export environment variables for the database process,
# this can be done here.
Comment 5 Caleb Tennis (RETIRED) gentoo-dev 2008-09-27 19:00:50 UTC
I am planning to move forward with these changes/fixes very soon unless someone from the pgsql team objects.
Comment 6 svrmarty 2008-09-28 21:16:16 UTC
just do it
Comment 7 Caleb Tennis (RETIRED) gentoo-dev 2008-09-28 22:52:56 UTC
committed (in 8.3.4 only).  Please try it out and let me know if you have any issues