Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have standard 'out-of-the-box' installation of

Linux version 3.0.1.stk64 (dfn@localhost.localdomain) (gcc version 4.5.1 20100924 (Red Hat 4.5.1-4) (GCC) ) #1 SMP Sat Aug 13 12:53:46 EDT 2011

It has postgresql 8.4 installed as (start script)


Data directory


My problem is that sometimes the Kernel decides to kill some of the Postgresql processes at times of low memory. I would like to inform kernel that Postgresql should not be chosen to be killed. I read from postgresql documentation ( that a command line echo -17 > /proc/self/oom_adj can be used to avoid the kill.

I tried to add this commandline to /etc/init.d/postgresql script but don't really know where to put it there.

Any pointers how to go about it? The scipt (/etc/init.d/postgresql) by the way is:

set -e

# Provides:             postgresql
# Required-Start:       $local_fs $remote_fs $network $time
# Required-Stop:        $local_fs $remote_fs $network $time
# Should-Start:         $syslog
# Should-Stop:          $syslog
# Default-Start:        2 3 4 5
# Default-Stop:         0 1 6
# Short-Description:    PostgreSQL RDBMS server

# Setting environment variables for the postmaster here does not work; please
# set them in /etc/postgresql/<version>/<cluster>/environment instead.

[ -r /usr/share/postgresql-common/init.d-functions ] || exit 0

. /usr/share/postgresql-common/init.d-functions

# versions can be specified explicitly
if [ -n "$2" ]; then
    versions="$2 $3 $4 $5 $6 $7 $8 $9"

case "$1" in
        for v in $versions; do
            $1 $v
        for v in $versions; do
            reload $v
        echo "Usage: $0 {start|stop|restart|reload|force-reload|status} [version ..]"
        exit 1

exit 0
share|improve this question

You should adjust oom_adj directly to postmaster pid, add a lines like this (NOT TESTED):

pid=`cat $PGDATA/ | head -1`
echo -17 > /proc/$pid/oom_adj
share|improve this answer
I can confirm that /proc/$postmasterpid/oom_adj default value is zero whereas sshd has -17 on redhat and debian. Shouldn't -17 be the default and a feature request be done? – user130370 Oct 25 '12 at 16:25
-17 is default in postgres-9.0 (and 9.1), i think version 8 is using too old init script to adjust oom-killer parameters. – Andrei Mikhaltsov Oct 25 '12 at 16:40
BTW oom_adj is obsolete, – Andrei Mikhaltsov Oct 25 '12 at 16:42
Thank you. Let's hope 9.x will be default soon :) – user130370 Oct 25 '12 at 16:50
Yes oom_score_adj should be used instead, but you need a recent kernel (not avail in rhel5). – user130370 Oct 25 '12 at 16:52

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.