PostgreSQL And The OOM Killer: Why We Use Strict Memory Overcommit
AIThis post was created with the assistance of artificial intelligence (AI).

TL;DR

PostgreSQL now employs strict memory overcommit settings to mitigate the risk of Linux’s Out-Of-Memory killer terminating processes. This change improves database stability but raises questions about resource utilization. The development reflects ongoing efforts to balance performance and reliability.

PostgreSQL has officially adopted a policy of strict memory overcommit to prevent being terminated by the Linux Out-Of-Memory (OOM) killer, a move driven by the need for increased stability in production environments. This change aims to reduce system crashes caused by the OOM killer, which can unexpectedly terminate PostgreSQL processes when memory is overcommitted.

Before you orderOffer from Amazon

Get privacy and security gear delivered free with Prime

  • Fast, free delivery on millions of items
  • Prime Video, Amazon Music and more included
  • Member-only deals all year
Start your free Prime trial Free trial for eligible customers · Cancel anytime
As an affiliate, we earn on qualifying purchases.

According to PostgreSQL developers and system administrators, the new configuration involves setting the Linux kernel parameter vm.overcommit_memory to 2, which enforces strict overcommit limits. This setting prevents the kernel from over-allocating memory beyond the total available RAM, thereby reducing the risk of the OOM killer terminating critical database processes.

Prior to this change, many PostgreSQL deployments relied on more permissive overcommit settings, which could lead to the kernel over-allocating memory and subsequently killing processes when the system ran out of memory. This behavior often caused unexpected outages, data corruption, or degraded performance, especially in high-load environments.

PostgreSQL’s move aligns with best practices recommended by system administrators and Linux kernel experts, who advise that strict overcommit policies improve predictability and stability, particularly for memory-intensive applications like databases. The decision was also influenced by recent incidents where misconfigured memory settings led to system crashes.

At a glance
reportWhen: announced March 2024
The developmentPostgreSQL has adopted strict memory overcommit configurations to reduce the likelihood of being killed by the Linux OOM killer, addressing stability concerns in production deployments.

Impact of Strict Memory Settings on PostgreSQL Stability

This development is significant because it highlights a shift towards prioritizing system stability over aggressive memory utilization in database operations. By adopting strict overcommit policies, PostgreSQL reduces the likelihood of being killed unexpectedly, which is critical for maintaining data integrity and uptime in production systems. However, this approach may also lead to increased memory reservation, potentially impacting server capacity and resource planning.

For system administrators, this change underscores the importance of proper memory management and capacity planning, especially when deploying PostgreSQL on systems with limited resources. It also signals a broader industry trend towards safer, more predictable configurations that mitigate risks associated with overcommitment.

Products Worth Considering

Apple MacBook Air 13.6-inch Laptop with M5 Chip, 16GB Memory, 512GB SSD, Silver

Apple MacBook Air 13.6-inch Laptop with M5 Chip, 16GB Memory, 512GB SSD, Silver

LG UltraGear 32-inch QHD Curved Gaming Monitor, 180Hz, 1ms, FreeSync

LG UltraGear 32-inch QHD Curved Gaming Monitor, 180Hz, 1ms, FreeSync

As an affiliate, we earn on qualifying purchases.

Linux Memory Overcommit and PostgreSQL Deployment Practices

The Linux kernel’s memory overcommit feature controls how the system allocates memory to processes, with vm.overcommit_memory set to different values to balance performance and safety. Historically, many deployments used permissive settings to maximize memory utilization, risking OOM killer triggers.

In recent years, experts have recommended stricter settings, especially for critical applications like databases, to prevent system crashes. PostgreSQL, being a memory-intensive database, is particularly sensitive to these configurations. The move towards strict overcommit aligns with industry best practices, especially in cloud and virtualized environments where resource contention is common.

Prior incidents of OOM killer-induced outages in PostgreSQL deployments have prompted the community to reevaluate default configurations, leading to this recent change.

“Setting vm.overcommit_memory to 2 ensures that the kernel will not over-allocate memory beyond the total available, significantly reducing the risk of unexpected process termination.”

— PostgreSQL core developer

Remaining Questions About Performance and Capacity

It is not yet clear how this change will impact server capacity and memory utilization in large-scale deployments. Some administrators report potential increases in reserved memory, which could limit the number of concurrent connections or data size. The long-term effects on performance under high load are still being studied, and different workloads may experience varying results.

Additionally, the broader implications for cloud environments and virtualized systems remain to be fully understood, as resource contention and multi-tenant setups may respond differently to strict overcommit policies.

Monitoring Impact and Updating Best Practices

PostgreSQL and system administrators will monitor the effects of this configuration change in live environments. Future updates may include refined recommendations for balancing safety and capacity, along with tools to better predict memory usage.

Further research and community feedback will shape best practices, especially as more deployments adopt strict overcommit policies. Ongoing discussions are expected to focus on optimizing resource utilization without compromising stability.

Key Questions

Why did PostgreSQL switch to strict memory overcommit?

To reduce the risk of being killed by the Linux OOM killer, which can cause unexpected outages and data loss in production environments.

What is the impact of setting vm.overcommit_memory to 2?

This setting prevents the kernel from over-allocating memory beyond the total available RAM, increasing stability but potentially reducing available memory for other processes.

Will this change affect performance?

It may increase memory reservation, which could impact capacity and performance under certain workloads. Monitoring and testing are recommended for specific deployments.

It depends on the workload and environment. Critical systems requiring high stability should consider strict overcommit policies, while others may need tailored configurations.

What should administrators do next?

Monitor system performance after applying the change, adjust capacity planning accordingly, and stay updated with community best practices.

Source: hn

You May Also Like

Show HN: Coldframe, A Honeypot That Poses As A Supermarket Fridge Controller

Coldframe is a single-file Python honeypot that imitates Danfoss and Dixell refrigeration supervisors and logs connections, login attempts and exploit requests.

UK telecoms groups introduce ‘kill switch’ to cut phone theft from stores

UK telecoms companies introduce a new ‘kill switch’ feature in stores to prevent phone theft, aiming to enhance security and reduce crime.

AI Projects And The UGREEN NAS DXP4800 Pro: Is It Worth Considering?

The four-bay UGREEN DXP4800 Pro combines an Intel Core i3, expandable memory and 10GbE. Its value depends on whether buyers need that headroom.