summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPavel Raiskup <praiskup@redhat.com>2015-03-21 22:46:53 +0100
committerPavel Raiskup <praiskup@redhat.com>2015-03-22 10:10:09 +0100
commit2ebc3bed7cdda15c45a948c2c9a7d4ab23b56d4e (patch)
tree1713f26d5496e301dd9cc0752718794e87cbe9a6
parentd529834d22549b48c54546d1fa463b93a0859025 (diff)
downloadpostgresql-setup-2ebc3bed7cdda15c45a948c2c9a7d4ab23b56d4e.tar.gz
postgresql-setup-2ebc3bed7cdda15c45a948c2c9a7d4ab23b56d4e.tar.xz
postgresql-setup-2ebc3bed7cdda15c45a948c2c9a7d4ab23b56d4e.zip
initscript: don't block system start-up by default
This commit should resolve complaints against pg_ctl -w usage from initscript (see rhbz#800534 for more info). The problem is that pg_ctl -w can block whole system startup too long - until the server is fully ready to accept connections. The commit 8c7b2cd5f6d9efb59568382cd8b6e88d9be517bb thus invented basically bad approach for initscript. Now, the "-w" option is used only if the PGSTARTWAIT is explicitly set to 1 by administrator. In this case, the PGSTARTTIMEOUT numeric value (in seconds) is respected (or limit 30 seconds is set by default). Otherwise, if PGSTARTWAIT is unset (default), initscript keeps checking only for the pidfile existence (at most PGSTARTTIMEOUT seconds). The hardwired 'sleep 2' command (activated before 8c7b2cd5f6 commit) is still not used - regular/default system startup should be a bit faster than before. * postgresql.init.in (start): Fix handling of PGDATA, PGPORT, PGOPTS and PGSCLS - to respect special quoting characters inside, we should escape the strings before passing those to command evaluation. Use printf %q as we use bash and we don't care too much about portability. Also, don't call postgresql-ctl with -w option if PGSTARTWAIT is empty or undefined. Implement pidfile polling for the cases PGSTARTWAIT is unset. Return success faster if server is already running. ($PGSTARTWAIT): New env variable. * postgresql-ctl.in: Don't parse $PGPORT into -o option as it is not needed. Unset PGPORT if the variable is empty - postgres server would fail with empty value. * configure.ac: Bump version to 3.3. * NEWS: Document bugfixes.
-rw-r--r--NEWS16
-rw-r--r--configure.ac2
-rw-r--r--postgresql-ctl.in11
-rw-r--r--postgresql.init.in68
4 files changed, 75 insertions, 22 deletions
diff --git a/NEWS b/NEWS
index d4dc148..d402ac2 100644
--- a/NEWS
+++ b/NEWS
@@ -1,6 +1,20 @@
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-New in 3.1 version
+Bugfixes in 3.3 version
+
+* The PGPORT/PGOPTS/.. variables should be correctly forwarded down from
+ the initstcript into postgresql-ctl.
+
+* Initscript's 'start' function again reports success if daemon is already
+ running.
+
+New in 3.3 version
+
+* New option PGSTARTWAIT for sysvinit systems.
+
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+New in 3.2 version
* The --new-systemd-unit option now cleans the recently created drop-in
directory if something goes wrong.
diff --git a/configure.ac b/configure.ac
index 7e7ae38..95368e5 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1,5 +1,5 @@
# Use the MAJ.MIN[~SUFF]. Note that X.X > X.X~SUFF!
-AC_INIT([postgresql-setup], [3.2], [praiskup@redhat.com])
+AC_INIT([postgresql-setup], [3.3], [praiskup@redhat.com])
AC_CONFIG_AUX_DIR(auxdir)
config_aux_dir=auxdir
AC_SUBST([config_aux_dir])
diff --git a/postgresql-ctl.in b/postgresql-ctl.in
index ad18004..569e4d3 100644
--- a/postgresql-ctl.in
+++ b/postgresql-ctl.in
@@ -22,9 +22,10 @@
# such extension, not the server itself).
test -n "$PGSCLS" && source scl_source enable $PGSCLS
-port=()
-if test "$1" = "start" && test -n "$PGPORT"; then
- port=(-o "-p $PGPORT")
-fi
+opts=()
+test "$1" = "start" && test -n "$PGOPTS" && opts=(-o "$PGOPTS")
-exec @bindir@/pg_ctl "$@" "${port[@]}"
+# cleanup possibly empty PGPORT
+test -z "$PGPORT" && unset PGPORT
+
+exec @bindir@/pg_ctl "$@" "${opts[@]}"
diff --git a/postgresql.init.in b/postgresql.init.in
index 7fca5f3..a078c28 100644
--- a/postgresql.init.in
+++ b/postgresql.init.in
@@ -117,11 +117,26 @@ start()
# The maximum waiting time PGSTARTTIMEOUT is set to 30 second to not hold
# the system too long. See `man pg_ctl & -w option`. This is not issue in
# case of systemd.
+ #
+ # PGSTARTWAIT turns on waiting for server to become fully ready to accept
+ # connection.
+
+ # clean the variable if not set to 1
+ test x1 != x"$PGSTARTWAIT" && PGSTARTWAIT=
+
+ # success if already started (pg_ctl -w could fail later)
+ status -p "$pidfile" postgres &>/dev/null && {
+ success "$PSQL_START"
+ echo
+ exit 0
+ }
run_cmd_as_dbadmin "\
- PGSCLS='${PGSCLS}' \
- @libexecdir@/postgresql-ctl start -D ${PGDATA} -s \
- -w -t ${PGSTARTTIMEOUT-30}" \
+ PGSCLS=$(printf %q "$PGSCLS") \
+ PGOPTS=$(printf %q "$PGOPTS") \
+ PGPORT=$(printf %q "$PGPORT") \
+ @libexecdir@/postgresql-ctl start -D $(printf %q "$PGDATA") -s \
+ ${PGSTARTWAIT:+-w -t ${PGSTARTTIMEOUT:-30}}" \
"$PGLOG" "$PGLOG"
if test $? -ne 0; then
@@ -131,18 +146,41 @@ start()
return
fi
- pid=`head -n 1 "$PGDATA/postmaster.pid" 2>/dev/null`
- if [ "x$pid" != x ]
- then
- success "$PSQL_START"
- touch "$lockfile"
- echo $pid > "$pidfile"
- echo
- else
- failure "$PSQL_START"
- echo
- script_result=1
- fi
+ # pg_ctl succeed, now recognize the pid number
+
+ pid=
+ if test x1 != x"$PGSTARTWAIT" ; then
+ # We don't wait for the full postgresql server start. In this case,
+ # wait for pidfile creation only. This should take _very_ short time in
+ # most cases but on highly overloaded machines - several seconds may
+ # not be enough. See rhbz#800534 and rhbz#1188942 for more info.
+ # Original waiting implementation by Jozef MlĂ­ch.
+
+ decounter=${PGSTARTTIMEOUT:-30}
+ while test "$decounter" -ge 0; do
+ pid=$(head -n 1 "$PGDATA/postmaster.pid" 2>/dev/null)
+
+ test "x$pid" != x && break
+
+ # pidfile does not exist yet, wait a sec more
+ decounter=$(( decounter - 1 ))
+ sleep 1
+ done
+ else
+ # pg_ctl -w succeed, pidfile must exist if everything is OK
+ pid=$(head -n 1 "$PGDATA/postmaster.pid" 2>/dev/null)
+ fi
+
+ if test "x$pid" != x; then
+ success "$PSQL_START"
+ touch "$lockfile"
+ echo "$pid" > "$pidfile"
+ echo
+ else
+ failure "$PSQL_START"
+ echo
+ script_result=1
+ fi
}
stop()