大网数据广告活动
服务器运维问答

Redis and Postgresql on same machine: vm.overcommit_memory=?

· 52CE 我爱测

In the Redis documentation it clearly states that vm.overcommit_memory should be set to 1 to ensure background saving newer fails: http://redis.io/topics/faq HOWEVER In postgresql documentation it says, that vm.overcommit_memory …

问题原文

原帖链接 · Niels Kristian · CC BY-SA 3.0

In the Redis documentation it clearly states that vm.overcommit_memory should be set to 1 to ensure background saving newer fails: http://redis.io/topics/faq

HOWEVER

In postgresql documentation it says, that vm.overcommit_memory should be set to 2 to avoid the post master process does not get killed by the oom killer: http://www.postgresql.org/docs/9.3/static/kernel-resources.html

Now, this is of cause contradictory. What should I do?

My redis db's have a limit of 20GB. The server has 252GB physical RAM. Postgresql rarely uses more than 100GB physical ram.

PS: I'm on ubuntu 14, Redis 3.0 and Postgresql 9.3

已采纳解答

原帖链接 · Daniel Vérité · CC BY-SA 3.0

You may go for the Redis recommendation, as the PostgreSQL packages for Ubuntu already implement the approach mentioned in the documentation against an ill-advised OOM kill of the postmaster process.

It's just after the section you're refering to in the doc. Excerpt from Linux Memory Overcommit

Another approach, which can be used with or without altering vm.overcommit_memory, is to set the process-specific oom_score_adj value for the postmaster process to -1000, thereby guaranteeing it will not be targeted by the OOM killer. The simplest way to do this is to execute

echo -1000 > /proc/self/oom_score_adj

in the postmaster's startup script just before invoking the postmaster. Note that this action must be done as root, or it will have no effect; so a root-owned startup script is the easiest place to do it. If you do this, you may also wish to build PostgreSQL with -DLINUX_OOM_SCORE_ADJ=0 added to CPPFLAGS. That will cause postmaster child processes to run with the normal oom_score_adj value of zero, so that the OOM killer can still target them at need.

On Ubuntu 14, the pg_ctlcluster script that starts a postgres instance has this:

   # have the postmaster start with increased OOM killer protection; 9.1 and
    # later has builtin support for resetting the adjustment of child processes
    if ($action eq 'start' && $version >= '9.1') {
        if (-w '/proc/self/oom_score_adj') {
            open F, '>/proc/self/oom_score_adj';
            print F "-900\n";
            close F;
        }
    }

so it assigns a fixed -900 to the postmaster's OOM score,

and /usr/lib/postgresql/9.3/bin/pg_config pg_config --cflags says:

-g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security -fPIC -pie -I/usr/include/mit-krb5 -DLINUX_OOM_SCORE_ADJ=0 -fno-omit-frame-pointer -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Wendif-labels -Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -fwrapv -fexcess-precision=standard -g

So the postmaster should never be selected by the OOM killer, but child backend process (one per connection) can.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2016-02-12)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。