Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit f23425f

Browse files
committed
Improve handling of OOM score adjustment in sample Linux start script.
Per a suggestion from Christoph Berg.
1 parent 5a421a4 commit f23425f

File tree

1 file changed

+19
-15
lines changed
  • contrib/start-scripts

1 file changed

+19
-15
lines changed

contrib/start-scripts/linux

+19-15
Original file line numberDiff line numberDiff line change
@@ -42,18 +42,17 @@ PGLOG="$PGDATA/serverlog"
4242

4343
# It's often a good idea to protect the postmaster from being killed by the
4444
# OOM killer (which will tend to preferentially kill the postmaster because
45-
# of the way it accounts for shared memory). Setting the OOM_SCORE_ADJ value
46-
# to -1000 will disable OOM kill altogether, which is a good thing for the
47-
# postmaster, but not so much for individual backends. If you enable this,
48-
# also uncomment the DAEMON_ENV line, which will instruct backends to set
49-
# their OOM adjustments back to the default setting of zero.
50-
#OOM_SCORE_ADJ=-1000
51-
#DAEMON_ENV="PG_OOM_ADJUST_FILE=/proc/self/oom_score_adj"
45+
# of the way it accounts for shared memory). To do that, uncomment these
46+
# three lines:
47+
#PG_OOM_ADJUST_FILE=/proc/self/oom_score_adj
48+
#PG_MASTER_OOM_SCORE_ADJ=-1000
49+
#PG_CHILD_OOM_SCORE_ADJ=0
5250
# Older Linux kernels may not have /proc/self/oom_score_adj, but instead
53-
# /proc/self/oom_adj, which works similarly except the disable value is -17.
54-
# For such a system, uncomment these two lines instead.
55-
#OOM_ADJ=-17
56-
#DAEMON_ENV="PG_OOM_ADJUST_FILE=/proc/self/oom_adj"
51+
# /proc/self/oom_adj, which works similarly except for having a different
52+
# range of scores. For such a system, uncomment these three lines instead:
53+
#PG_OOM_ADJUST_FILE=/proc/self/oom_adj
54+
#PG_MASTER_OOM_SCORE_ADJ=-17
55+
#PG_CHILD_OOM_SCORE_ADJ=0
5756

5857
## STOP EDITING HERE
5958

@@ -80,13 +79,19 @@ test -x $DAEMON ||
8079
fi
8180
}
8281

82+
# If we want to tell child processes to adjust their OOM scores, set up the
83+
# necessary environment variables. Can't just export them through the "su".
84+
if [ -e "$PG_OOM_ADJUST_FILE" -a -n "PG_CHILD_OOM_SCORE_ADJ" ]
85+
then
86+
DAEMON_ENV="PG_OOM_ADJUST_FILE=$PG_OOM_ADJUST_FILE PG_OOM_ADJUST_VALUE=$PG_CHILD_OOM_SCORE_ADJ"
87+
fi
88+
8389

8490
# Parse command line parameters.
8591
case $1 in
8692
start)
8793
echo -n "Starting PostgreSQL: "
88-
test x"$OOM_SCORE_ADJ" != x && echo "$OOM_SCORE_ADJ" > /proc/self/oom_score_adj
89-
test x"$OOM_ADJ" != x && echo "$OOM_ADJ" > /proc/self/oom_adj
94+
test -e "$PG_OOM_ADJUST_FILE" && echo "$PG_MASTER_OOM_SCORE_ADJ" > "$PG_OOM_ADJUST_FILE"
9095
su - $PGUSER -c "$DAEMON_ENV $DAEMON -D '$PGDATA' &" >>$PGLOG 2>&1
9196
echo "ok"
9297
;;
@@ -98,8 +103,7 @@ case $1 in
98103
restart)
99104
echo -n "Restarting PostgreSQL: "
100105
su - $PGUSER -c "$PGCTL stop -D '$PGDATA' -s -m fast -w"
101-
test x"$OOM_SCORE_ADJ" != x && echo "$OOM_SCORE_ADJ" > /proc/self/oom_score_adj
102-
test x"$OOM_ADJ" != x && echo "$OOM_ADJ" > /proc/self/oom_adj
106+
test -e "$PG_OOM_ADJUST_FILE" && echo "$PG_MASTER_OOM_SCORE_ADJ" > "$PG_OOM_ADJUST_FILE"
103107
su - $PGUSER -c "$DAEMON_ENV $DAEMON -D '$PGDATA' &" >>$PGLOG 2>&1
104108
echo "ok"
105109
;;

0 commit comments

Comments
 (0)