Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Lane2014-06-19 00:12:47 +0000
committerTom Lane2014-06-19 00:12:51 +0000
commitdf8b7bc9ffff5b00aacff774600b569992cddeb8 (patch)
treed9136c85540b121ff5d229320cc761d336f95107 /contrib/start-scripts/linux
parent960661980beb50c5d21e4b2855ae109e9a130326 (diff)
Improve our mechanism for controlling the Linux out-of-memory killer.
Arrange for postmaster child processes to respond to two environment variables, PG_OOM_ADJUST_FILE and PG_OOM_ADJUST_VALUE, to determine whether they reset their OOM score adjustments and if so to what. This is superior to the previous design involving #ifdef's in several ways. The behavior is now available in a default build, and both ends of the adjustment --- the original adjustment of the postmaster's level and the subsequent readjustment by child processes --- can now be controlled in one place, namely the postmaster launch script. So it's no longer necessary for the launch script to act on faith that the server was compiled with the appropriate options. In addition, if someone wants to use an OOM score other than zero for the child processes, that doesn't take a recompile anymore; and we no longer have to cater separately to the two different historical kernel APIs for this adjustment. Gurjeet Singh, somewhat revised by me
Diffstat (limited to 'contrib/start-scripts/linux')
-rw-r--r--contrib/start-scripts/linux15
1 files changed, 9 insertions, 6 deletions
diff --git a/contrib/start-scripts/linux b/contrib/start-scripts/linux
index b950cf512c3..bab8b0efc67 100644
--- a/contrib/start-scripts/linux
+++ b/contrib/start-scripts/linux
@@ -43,14 +43,17 @@ PGLOG="$PGDATA/serverlog"
# It's often a good idea to protect the postmaster from being killed by the
# OOM killer (which will tend to preferentially kill the postmaster because
# of the way it accounts for shared memory). Setting the OOM_SCORE_ADJ value
-# to -1000 will disable OOM kill altogether. If you enable this, you probably
-# want to compile PostgreSQL with "-DLINUX_OOM_SCORE_ADJ=0", so that
-# individual backends can still be killed by the OOM killer.
+# to -1000 will disable OOM kill altogether, which is a good thing for the
+# postmaster, but not so much for individual backends. If you enable this,
+# also uncomment the DAEMON_ENV line, which will instruct backends to set
+# their OOM adjustments back to the default setting of zero.
#OOM_SCORE_ADJ=-1000
+#DAEMON_ENV="PG_OOM_ADJUST_FILE=/proc/self/oom_score_adj"
# Older Linux kernels may not have /proc/self/oom_score_adj, but instead
# /proc/self/oom_adj, which works similarly except the disable value is -17.
-# For such a system, enable this and compile with "-DLINUX_OOM_ADJ=0".
+# For such a system, uncomment these two lines instead.
#OOM_ADJ=-17
+#DAEMON_ENV="PG_OOM_ADJUST_FILE=/proc/self/oom_adj"
## STOP EDITING HERE
@@ -84,7 +87,7 @@ case $1 in
echo -n "Starting PostgreSQL: "
test x"$OOM_SCORE_ADJ" != x && echo "$OOM_SCORE_ADJ" > /proc/self/oom_score_adj
test x"$OOM_ADJ" != x && echo "$OOM_ADJ" > /proc/self/oom_adj
- su - $PGUSER -c "$DAEMON -D '$PGDATA' &" >>$PGLOG 2>&1
+ su - $PGUSER -c "$DAEMON_ENV $DAEMON -D '$PGDATA' &" >>$PGLOG 2>&1
echo "ok"
;;
stop)
@@ -97,7 +100,7 @@ case $1 in
su - $PGUSER -c "$PGCTL stop -D '$PGDATA' -s -m fast -w"
test x"$OOM_SCORE_ADJ" != x && echo "$OOM_SCORE_ADJ" > /proc/self/oom_score_adj
test x"$OOM_ADJ" != x && echo "$OOM_ADJ" > /proc/self/oom_adj
- su - $PGUSER -c "$DAEMON -D '$PGDATA' &" >>$PGLOG 2>&1
+ su - $PGUSER -c "$DAEMON_ENV $DAEMON -D '$PGDATA' &" >>$PGLOG 2>&1
echo "ok"
;;
reload)