禁止Linux内核杀死postgresql进程

前端之家收集整理的这篇文章主要介绍了禁止Linux内核杀死postgresql进程前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我有标准的’开箱即用’安装
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

它安装了postgresql 8.4作为(启动脚本)

/etc/init.d/postgresql

数据目录

/etc/postgresql/8.4/main/

我的问题是,有时内核决定在内存不足的情况下杀死一些Postgresql进程.我想通知内核不应该选择Postgresql被杀死.我从postgresql文档(http://www.postgresql.org/docs/9.1/static/kernel-resources.html)中读到命令行echo -17> / proc / self / oom_adj可用于避免kill.

我试图将此命令行添加到/etc/init.d/postgresql脚本,但实际上并不知道将它放在哪里.

任何指针如何去做?该方法的scipt(/etc/init.d/postgresql)是:

#!/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

解决方法

你应该直接调整oom_adj到postmaster pid,添加这样的行(NOT TESTED):
pid=`cat $PGDATA/postmaster.pid | head -1`
echo -17 > /proc/$pid/oom_adj
原文链接:https://www.f2er.com/linux/399200.html

猜你在找的Linux相关文章