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.
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).
(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.
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 $? }
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.
I am planning to move forward with these changes/fixes very soon unless someone from the pgsql team objects.
just do it
committed (in 8.3.4 only). Please try it out and let me know if you have any issues