Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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)

/etc/init.d/postgresql

Data directory

/etc/postgresql/8.4/main/

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 (http://www.postgresql.org/docs/9.1/static/kernel-resources.html) 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:

#!/bin/sh
set -e

### BEGIN INIT INFO
# 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
### END INIT INFO

# 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"
else
    get_versions
fi

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

exit 0
share|improve this question

1 Answer 1

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

pid=`cat $PGDATA/postmaster.pid | 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? –  coincoin 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, kernel.org/doc/Documentation/ABI/obsolete/proc-pid-oom_adj –  Andrei Mikhaltsov Oct 25 '12 at 16:42
    
Thank you. Let's hope 9.x will be default soon :) –  coincoin Oct 25 '12 at 16:50
    
Yes oom_score_adj should be used instead, but you need a recent kernel (not avail in rhel5). –  coincoin Oct 25 '12 at 16:52

Your Answer

 
discard

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.