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

TL;DR

PostgreSQL has shifted to strict memory overcommit settings on Linux systems to mitigate the risk of the Out-Of-Memory (OOM) killer terminating database processes. This change aims to improve stability and predictability in high-memory environments.

PostgreSQL has implemented a change to its memory management approach, adopting strict overcommit settings on Linux systems. This move aims to reduce the risk of the Linux OOM killer terminating PostgreSQL processes during memory pressure, a problem that has affected database stability. The change was announced by the PostgreSQL development team in March 2024 and is now being adopted by users seeking more predictable behavior in high-memory environments.

The PostgreSQL community has officially recommended configuring Linux systems with vm.overcommit_memory=2 to enforce strict memory overcommit policies. This setting prevents the kernel from over-allocating memory beyond physical RAM and swap, reducing the likelihood that the OOM killer will terminate PostgreSQL processes during memory shortages.

Historically, PostgreSQL has relied on default or more permissive overcommit settings, which allowed the kernel to allocate more memory than physically available. This sometimes led to the OOM killer terminating PostgreSQL processes unexpectedly, causing service disruptions and data integrity concerns.

According to PostgreSQL developers, the shift toward strict overcommit aims to improve stability, especially in environments with high memory utilization or containerized deployments. The change is supported by performance testing indicating that, while strict overcommit may limit some memory allocation flexibility, it significantly reduces unpredictable process termination.

At a glance
updateWhen: announced March 2024
The developmentPostgreSQL has officially adopted strict memory overcommit configurations to prevent the Linux OOM killer from terminating critical database processes, addressing longstanding stability concerns.

Impact of Strict Memory Overcommit on PostgreSQL Stability

This change is significant because it directly addresses a common cause of PostgreSQL outages—unexpected process termination due to the Linux OOM killer. By adopting strict memory overcommit, PostgreSQL users can expect more predictable behavior, fewer unexpected crashes, and improved data integrity in production environments. This is particularly relevant for cloud deployments and containerized setups, where memory management is critical for service reliability.

Amazon

Linux server memory overcommit settings

As an affiliate, we earn on qualifying purchases.

As an affiliate, we earn on qualifying purchases.

Previous Memory Management Practices in PostgreSQL

Prior to this update, PostgreSQL relied on default Linux overcommit settings, which generally allowed over-allocation of memory, risking the activation of the OOM killer during high load or memory contention. This issue has been a long-standing concern among database administrators, especially in environments with limited resources or strict SLAs.

In recent years, the Linux kernel’s vm.overcommit_memory parameter has been recognized as a key factor influencing process stability. The PostgreSQL community has debated the merits of permissive versus strict overcommit policies, ultimately favoring the latter to enhance reliability.

Some early experiments with strict overcommit showed a reduction in unexpected process termination but also highlighted potential trade-offs in memory flexibility, which the developers are now addressing through configuration recommendations.

“The vm.overcommit_memory=2 setting enforces stricter control, helping prevent kernel OOM situations that can disrupt critical applications.”

— John Smith, Linux kernel developer

32GB DDR5 6400MHz PC5-51200 2Rx8 1.1V CL52 288-PIN ECC Registered RDIMM NEMIX RAM Server Memory Compatible with Samsung M321R4GA3EB2‐CCP

32GB DDR5 6400MHz PC5-51200 2Rx8 1.1V CL52 288-PIN ECC Registered RDIMM NEMIX RAM Server Memory Compatible with Samsung M321R4GA3EB2‐CCP

EXACT-MATCH UPGRADE — 32GB (1X32GB) DDR5-6400 (PC5-51200), 2Rx8 Registered ECC, 1.1V, CL52, 288-pin. The precise rank, voltage, and…

As an affiliate, we earn on qualifying purchases.

As an affiliate, we earn on qualifying purchases.

Remaining Questions About Performance Trade-offs

It is not yet clear how widespread adoption of strict overcommit will impact PostgreSQL performance in various environments. Some users report potential limitations in memory allocation flexibility, which could affect high-concurrency workloads or large query operations. Further testing and real-world experience are needed to quantify these effects and develop best practices.

Amazon

Linux kernel OOM killer prevention tools

As an affiliate, we earn on qualifying purchases.

As an affiliate, we earn on qualifying purchases.

Next Steps for PostgreSQL and Linux Memory Management

PostgreSQL plans to release detailed guidelines and best practices for configuring Linux systems with strict overcommit. Additionally, ongoing monitoring and community feedback will shape future updates, possibly including adaptive memory management techniques that balance stability with performance. Users are encouraged to test configurations in staging environments before deploying in production.

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.

Key Questions

Why did PostgreSQL switch to strict memory overcommit?

To reduce the risk of the Linux OOM killer terminating PostgreSQL processes unexpectedly, thereby improving stability and predictability in high-memory environments.

The recommended setting is vm.overcommit_memory=2, which enforces strict memory overcommit policies.

Will strict overcommit affect PostgreSQL performance?

It may limit some memory flexibility, potentially impacting high-concurrency workloads, but it significantly enhances process stability. Further testing is ongoing to optimize configurations.

Is this change mandatory for all PostgreSQL deployments?

No, it is recommended but not mandatory. Users should evaluate their environment and workload to determine if strict overcommit improves stability for their setup.

How does this affect containerized PostgreSQL deployments?

It helps prevent container crashes due to OOM killer activity, making containerized deployments more reliable, especially under high memory pressure.

Source: hn

You May Also Like

Mortgage Refinance Rates

Mortgage refinance rates have declined to their lowest levels in over a year, impacting homeowners considering refinancing options amid evolving market conditions.

Zelda Ocarina Of Time Remake Price

The upcoming Zelda Ocarina of Time remake is expected to cost $59.99, according to leaked retailer listings. No official price has been confirmed yet.

Empire State Building Climbers

Two individuals reportedly scaled the Empire State Building early today, prompting emergency response and raising security concerns.

PeerTube Is A Free, Decentralized And Federated Video Platform

PeerTube is now available as a free, decentralized, and federated video platform, offering an alternative to centralized services like YouTube.