Skip to content

Commit 8c7b2cd

Browse files
committed
init: add PGSTARTTIMEOUT config env variable
* postgresql.init.in (PGSTARTTIMEOUT): New variable. (start): Use postgresql-ctl and respect PGSTARTTIMEOUT. * postgresql.service.in: Better document the timeouts. (PGSTARTTIMEOUT): New env variable. (ExecStart): Respect PGSTARTTIMEOUT. * NEWS: Document.
1 parent 00b185f commit 8c7b2cd

File tree

3 files changed

+24
-6
lines changed

3 files changed

+24
-6
lines changed

NEWS

+2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ New in 3.0 version
1818
* The sysvinit support should be OK finally, sysvinit system is now
1919
automatically detected without --with-sysvinit configure option.
2020

21+
* The starting timeout is now configurable via PGSTARTTIMEOUT.
22+
2123
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2224

2325
New in 2.0 version

postgresql.init.in

+14-4
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ PG_OOM_ADJ=-17
7373

7474
export PGDATA
7575
export PGPORT
76+
export PGSTARTTIMEOUT
7677

7778
lockfile="/var/lock/subsys/${NAME}"
7879

@@ -111,13 +112,22 @@ start()
111112
# is already running. We should probably 'status' first and start only if
112113
# postmaster is down. This just unnecessarily wastes time and generates
113114
# too much (false) rush in $PGLOG.
115+
#
116+
# The maximum waiting time PGSTARTTIMEOUT is set to 30 second to not hold
117+
# the system too long. See `man pg_ctl & -w option`. This is not issue in
118+
# case of systemd.
119+
114120
run_cmd_as_dbadmin \
115-
"$PGENGINE/postgres ${PGPORT+-o "-p $PGPORT"} \
116-
-D '$PGDATA' ${PGOPTS} &" \
121+
"@libexecdir@/postgresql-ctl start -D ${PGDATA} -s \
122+
-w -t ${PGSTARTTIMEOUT-30}" \
117123
"$PGLOG" "$PGLOG"
118124

119-
# TODO: parametrize
120-
sleep 2
125+
if test $? -ne 0; then
126+
failure "$PSQL_START"
127+
echo
128+
script_result=1
129+
return
130+
fi
121131

122132
pid=`head -n 1 "$PGDATA/postmaster.pid" 2>/dev/null`
123133
if [ "x$pid" != x ]

postgresql.service.in

+8-2
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,24 @@ OOMScoreAdjust=-1000
2626
Environment=PG_OOM_ADJUST_FILE=/proc/self/oom_score_adj
2727
Environment=PG_OOM_ADJUST_VALUE=0
2828

29+
# Maximum number of seconds pg_ctl will wait for postgres to start. Note that
30+
# PGSTARTTIMEOUT should be less than TimeoutSec value.
31+
Environment=PGSTARTTIMEOUT=270
32+
2933
@PGDATA_ENVIRONMENT@
3034

3135
ExecStartPre=@libexecdir@/postgresql-check-db-dir %N
3236

3337
# Use convenient postgresql-ctl wrapper instead of directly pg_ctl. See the
3438
# postgresql-ctl file itself for more info.
3539

36-
ExecStart=@libexecdir@/postgresql-ctl start -D ${PGDATA} -s -w -t 300
40+
ExecStart=@libexecdir@/postgresql-ctl start -D ${PGDATA} -s -w -t ${PGSTARTTIMEOUT}
3741
ExecStop=@libexecdir@/postgresql-ctl stop -D ${PGDATA} -s -m fast
3842
ExecReload=@libexecdir@/postgresql-ctl reload -D ${PGDATA} -s
3943

40-
# Give a reasonable amount of time for the server to start up/shut down
44+
# Give a reasonable amount of time for the server to start up/shut down.
45+
# Ideally, the timeout for starting PostgreSQL server should be handled more
46+
# nicely by pg_ctl in ExecStart, so keep its timeout smaller than this value.
4147
TimeoutSec=300
4248

4349
[Install]

0 commit comments

Comments
 (0)