@@ -42,18 +42,17 @@ PGLOG="$PGDATA/serverlog"
42
42
43
43
# It's often a good idea to protect the postmaster from being killed by the
44
44
# 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
52
50
# 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
57
56
58
57
# # STOP EDITING HERE
59
58
@@ -80,13 +79,19 @@ test -x $DAEMON ||
80
79
fi
81
80
}
82
81
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
+
83
89
84
90
# Parse command line parameters.
85
91
case $1 in
86
92
start)
87
93
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 "
90
95
su - $PGUSER -c " $DAEMON_ENV $DAEMON -D '$PGDATA ' &" >> $PGLOG 2>&1
91
96
echo " ok"
92
97
;;
@@ -98,8 +103,7 @@ case $1 in
98
103
restart)
99
104
echo -n " Restarting PostgreSQL: "
100
105
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 "
103
107
su - $PGUSER -c " $DAEMON_ENV $DAEMON -D '$PGDATA ' &" >> $PGLOG 2>&1
104
108
echo " ok"
105
109
;;
0 commit comments