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

TL;DR

PostgreSQL now employs strict memory overcommit configurations to mitigate the risk of Linux’s Out-Of-Memory killer activating during heavy workloads. This approach aims to improve database stability and predictability, especially in resource-constrained systems.

PostgreSQL has implemented a policy of strict memory overcommit to prevent the Linux Out-Of-Memory (OOM) killer from terminating database processes during high memory usage. This change aims to improve stability and predictability for users running PostgreSQL in environments with limited or heavily shared memory resources, making it a significant development for database administrators and system architects.

The PostgreSQL community announced in March 2024 that it now recommends configuring Linux systems with strict memory overcommit settings, specifically setting vm.overcommit_memory=2. This setting instructs the kernel to refuse memory allocations that exceed the total available RAM plus swap, thereby preventing the OOM killer from activating unexpectedly during intensive workloads.

Traditionally, Linux systems default to a more permissive overcommit setting, which allows applications to allocate more memory than physically available, relying on the kernel’s heuristics. However, this can lead to situations where the OOM killer terminates PostgreSQL processes to free memory, risking data loss and service disruption. The new configuration aims to avoid this by ensuring that memory allocations are more predictable and controlled.

PostgreSQL developers and system administrators have expressed that this approach helps maintain database stability, especially in shared hosting or cloud environments where resource contention is common. The change aligns with best practices for managing memory-intensive applications on Linux.

At a glance
reportWhen: announced March 2024
The developmentPostgreSQL has officially adopted strict memory overcommit settings to prevent the Linux OOM killer from terminating database processes during peak usage.

Impact of Strict Memory Overcommit on PostgreSQL Stability

This shift to strict memory overcommit settings is significant because it directly addresses the risk of unexpected process termination due to the Linux OOM killer, which can cause data corruption or service outages. By controlling memory allocation more tightly, PostgreSQL deployments are less likely to be interrupted during peak loads, leading to more reliable operations.

For system administrators, this means configuring Linux hosts with vm.overcommit_memory=2 and monitoring memory usage becomes essential. It also influences best practices for deploying PostgreSQL in containerized or cloud environments where resource limits are enforced.

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 and PostgreSQL Stability

Linux’s default memory overcommit behavior has historically allowed applications to allocate more memory than physically available, trusting the kernel to handle over-commitment heuristics. While this can improve performance in some cases, it also increases the risk of triggering the OOM killer, which terminates processes to free memory. For database systems like PostgreSQL, such interruptions can lead to transaction failures, data corruption, or crashes.

Over the past few years, there has been a growing consensus among database administrators and Linux experts that more conservative memory management policies improve stability, especially in production systems. PostgreSQL’s adoption of strict overcommit aligns with this trend, emphasizing predictable behavior and reducing the likelihood of unexpected outages.

Prior to this change, PostgreSQL users often had to manually tune kernel parameters or rely on external monitoring to mitigate risks associated with overcommitment, which could be complex and error-prone.

“Implementing strict memory overcommit helps prevent the Linux OOM killer from terminating PostgreSQL processes during high memory usage, improving overall stability.”

— PostgreSQL Development Team

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 Compatibility

It is still unclear how widespread adoption of strict overcommit will impact performance in various workloads, especially in environments with high memory demands. Some users report potential limitations or the need for additional tuning, but comprehensive data on long-term stability and performance is not yet available.

Furthermore, the precise impact on containerized deployments and cloud environments remains to be fully evaluated, as different orchestration tools may interact differently with Linux memory settings.

Amazon

Linux kernel tuning for database stability

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 developers plan to monitor the implementation’s impact across diverse environments and update best practices accordingly. System administrators are advised to test strict overcommit settings in staging before deploying in production.

Additional research and community feedback will help refine recommendations, potentially leading to further kernel or PostgreSQL enhancements to optimize stability and performance.

Amazon

Memory overcommit configuration for PostgreSQL

As an affiliate, we earn on qualifying purchases.

As an affiliate, we earn on qualifying purchases.

Key Questions

What is Linux’s memory overcommit setting?

It controls how Linux handles memory allocation requests that exceed available physical memory, with vm.overcommit_memory=2 rejecting over-allocations that cannot be safely fulfilled.

Why is PostgreSQL adopting strict overcommit now?

To prevent the Linux OOM killer from terminating PostgreSQL processes during high memory usage, thereby improving stability and data integrity.

Will this affect database performance?

Potentially, as stricter overcommit policies may limit some memory allocations. However, the goal is to improve predictability and reduce unexpected process termination.

It is recommended for production environments where stability is critical, especially in resource-constrained or shared systems. Testing in staging environments is advised first.

What should system administrators do now?

Configure Linux hosts with vm.overcommit_memory=2 and monitor memory usage closely to ensure stability without sacrificing performance.

Source: hn

You May Also Like

OpenWiki: CLI That Writes And Maintains Agent Documentation For Your Codebase

OpenWiki introduces a command-line tool that automatically generates and maintains agent documentation within codebases, streamlining developer workflows.

Building and shipping Mac and iOS apps without opening Xcode

Apple introduces a new method for developers to build and ship Mac and iOS apps without launching Xcode, streamlining the development process.

Ensuring Quality in Open-Source Software Projects

Building robust open-source projects requires strategies that ensure quality and community engagement, and here’s how you can start…

Maintainability Metrics That Predict Long‑Term Success

Predicting long-term software success relies on maintainability metrics that reveal how easily a system can adapt and evolve over time.