Question

How can i disable overcommit_memory?

Posted May 25, 2019 761 views
DebianPostgreSQLLinux Commands

I have a postgresql server and i’m trying to disable the overcoomit_memory on my server.

It should be simple, a single line command: sysctl -w vm.overcommit_memory=2
No need to reboot.

But as i ran the command, my server will “stop” and then the only way to get it responding again is rebooting the droplet.

Does anyone knows why it happen and how to fix?

1: https://www.postgresql.org/docs/9.6/kernel-resources.html
2: https://www.hivelocity.net/kb/how-does-memory-overcommit-affect-postgresql/
3: http://engineering.pivotal.io/post/virtual_memory_settings_in_linux_-_the_problem_with_overcommit/

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

×
1 answer

Hi @agalysson,

Memory overcommit can be disabled by vm.overcommit_memory=2

0 is the default mode, where kernel heuristically determines the allocation by calculating the free memory compared to the allocation request being made. And setting it to 1 enables the wizardry mode, where kernel always advertises that it has enough free memory for any allocation. Setting to 2, means that processes can only allocate up to a configurable amount (overcommit_ratio) of RAM and will start getting allocation failure or OOM messages when it goes beyond that amount

Is it safe to do so, no. I haven’t seen any proper use case where disabling memory overcommit actually helped, unless you are 100% certain of the workload and hardware capacity. In case you are interested, install kernel-docs package and go to /Documentation/sysctl/vm.txt to read more, or read it online.

If you set vm.overcommitmemory=2 then it will overcommit up to the percentage of physical RAM configured in vm.overcommitratio (default is 50%).

echo 0/1/2 > /proc/sys/vm/overcommit_memory 

This will not survive a reboot. For persistence, put this in /etc/sysctl.conf file:

vm.overcommit_memory=X

and run sysctl -p. No need to reboot.

Regards,
Kalin

Submit an Answer