PostgreSQL And The OOM Killer: Why We Use Strict Memory Overcommit

TL;DR

PostgreSQL developers have implemented strict memory overcommit policies to mitigate the risk of Linux’s OOM killer terminating database processes. This change aims to improve stability and predictability in high-memory environments.

PostgreSQL has officially adopted a policy of strict memory overcommit to reduce the likelihood of being terminated by the Linux Out-Of-Memory (OOM) killer, a move aimed at enhancing database stability in high-memory environments. This change responds to longstanding issues where the OOM killer would unpredictably terminate PostgreSQL processes under memory pressure, causing outages and data consistency concerns.

According to PostgreSQL developers and system administrators, the new configuration enforces stricter control over memory allocation, preventing the operating system from overcommitting memory beyond physical limits. This is achieved by adjusting kernel parameters such as vm.overcommit_memory to a more conservative setting.

Historically, Linux’s default overcommit behavior allows processes to allocate more memory than physically available, relying on the kernel’s heuristics. However, in high-memory database workloads, this can lead to the OOM killer terminating PostgreSQL processes to free memory, disrupting service and risking data integrity. The new approach minimizes this risk by limiting overcommit.

PostgreSQL’s documentation now recommends setting vm.overcommit_memory to 2, which enforces strict overcommit policies, and suggests additional kernel tuning for environments with heavy memory usage. The change is part of ongoing efforts to improve database reliability and predictability in production settings.

At a glance
reportWhen: announced March 2024
The developmentPostgreSQL now uses strict memory overcommit settings to prevent the Linux OOM killer from terminating its processes, addressing stability concerns.

Why Strict Memory Overcommit Improves PostgreSQL Stability

This development is significant because it directly impacts the reliability of PostgreSQL deployments, especially in cloud and large-scale environments where memory pressure is common. By preventing the OOM killer from terminating PostgreSQL processes unexpectedly, system administrators can achieve more predictable performance and minimize downtime.

Furthermore, this shift aligns PostgreSQL with best practices for managing memory in Linux, emphasizing the importance of explicit kernel tuning in high-performance database environments. It also highlights the ongoing need for close coordination between database configuration and underlying operating system settings to ensure stability.

Amazon

Linux server memory overcommit settings

As an affiliate, we earn on qualifying purchases.

As an affiliate, we earn on qualifying purchases.

Background on Memory Management in Linux and PostgreSQL

Linux’s default memory overcommit behavior has historically allowed processes to allocate more memory than physically available, relying on heuristics that sometimes lead to the OOM killer terminating processes when memory is exhausted. This has been a known challenge for database systems like PostgreSQL, which require stable, predictable memory management.

Prior to this change, many PostgreSQL deployments relied on heuristics and manual tuning to mitigate OOM risks, but incidents of unexpected process termination persisted. The move to strict overcommit policies represents a more systematic approach, aligning with Linux kernel recommendations and best practices for mission-critical applications.

This change was prompted by reports from system administrators and ongoing discussions within the PostgreSQL community about improving stability in memory-intensive workloads.

“Implementing strict memory overcommit policies reduces the risk of the OOM killer terminating PostgreSQL processes, leading to more stable database operations.”

— PostgreSQL core developer

Tricks for Python performance optimization and memory management - Tips for efficient resource usage and speedup using profiling tools - (Japanese Edition)

Tricks for Python performance optimization and memory management – Tips for efficient resource usage and speedup using profiling tools – (Japanese Edition)

As an affiliate, we earn on qualifying purchases.

As an affiliate, we earn on qualifying purchases.

Remaining Questions About Long-Term Effects and Implementation

It is not yet clear how widespread adoption of strict overcommit policies will impact overall system performance under various workloads. Some experts warn that overly conservative settings might lead to underutilization of available memory, potentially impacting performance. Further monitoring and testing are needed to optimize configurations for different environments.

Additionally, there is ongoing discussion about how best to balance strict overcommit with the need for high memory utilization in cloud-native deployments, where resource efficiency is critical. The long-term effects on other Linux-based applications are also still being studied.

High-Performance Memory Management: A Practical Guide to Kernel Optimization: Learn NUMA Architecture, Reduce Page Faults, Eliminate Memory Fragmentation, and Improve Linux System Performance

High-Performance Memory Management: A Practical Guide to Kernel Optimization: Learn NUMA Architecture, Reduce Page Faults, Eliminate Memory Fragmentation, and Improve Linux System Performance

As an affiliate, we earn on qualifying purchases.

As an affiliate, we earn on qualifying purchases.

Next Steps for PostgreSQL and Linux Memory Tuning

PostgreSQL developers plan to continue refining recommendations for memory configuration, including detailed guidance for various workload types. System administrators are encouraged to test these settings in staging environments before deployment in production.

Linux kernel maintainers and the PostgreSQL community are expected to collaborate on developing best practices for memory management, potentially leading to updates in kernel defaults or new tuning tools. Monitoring tools and metrics will play a key role in assessing the impact of these changes over time.

Ubuntu 26.04 LTS Linux Bootable USB Flash Drive (Server)

Ubuntu 26.04 LTS Linux Bootable USB Flash Drive (Server)

🚀 Latest Ubuntu 26.04 LTS (Long-Term Support) Get the newest stable release of Ubuntu 26.04 LTS with long-term…

As an affiliate, we earn on qualifying purchases.

As an affiliate, we earn on qualifying purchases.

Key Questions

What is memory overcommit, and why does it matter for PostgreSQL?

Memory overcommit is a Linux kernel setting that controls whether processes can allocate more memory than physically available. For PostgreSQL, strict overcommit reduces the risk of the OOM killer terminating processes unexpectedly, improving stability.

How do I configure my Linux system for PostgreSQL with strict overcommit?

Set vm.overcommit_memory to 2 in your kernel parameters and adjust related settings like vm.overcommit_ratio as needed. Consult PostgreSQL and Linux documentation for specific tuning guidance.

Will strict overcommit settings impact system performance?

Potentially, yes. Overly conservative settings might lead to underutilized memory, but they significantly reduce the risk of process termination. Proper testing is recommended to find the optimal balance.

Is this change applicable to all Linux distributions?

Most Linux distributions support these kernel parameters, but implementation details may vary. Always verify and test configurations in your environment before deploying.

Source: hn

You May Also Like

The Safari MCP Server For Web Developers

Apple introduces the Safari MCP server, a new tool for web developers to streamline testing and deployment. Details are confirmed, but some features remain undisclosed.

Africans Are Turning To Starlink

Many Africans are turning to SpaceX’s Starlink satellite internet to improve connectivity, especially in underserved regions, amid ongoing infrastructure challenges.