我有标准的“开箱即用”安装
Linux version 3.0.1.stk64 ([email protected]) (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
来避免被杀死。
我尝试将此命令行添加到/etc/init.d/postgresql
脚本中,但不知道将其放在哪里。
有什么指示可以指导如何操作吗?/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
答案1
您应该将 oom_adj 直接调整为 postmaster pid,添加如下行(未经测试):
pid=`cat $PGDATA/postmaster.pid | head -1`
echo -17 > /proc/$pid/oom_adj