liveBook · Manning

Oom killer

As explained in PostgreSQL Mistakes and How to Avoid Them

The OOM killer is a Linux kernel mechanism that terminates selected processes when system memory is critically exhausted.

The Linux OOM killer terminates processes when PostgreSQL and other workloads exhaust system memory. PostgreSQL may then terminate all active backends, enter crash recovery, and potentially fail over to a replica. section 6.2

A tempting configuration such as shared_buffers = 12GB and work_mem = 2GB can become dangerous: work_mem may be allocated per plan node, session, and parallel operation. With many connected sessions, complex queries can exhaust RAM quickly. Keep work_mem conservative, then raise it only for sessions or queries that need it; otherwise operations may spill to slower temporary files. section 6.2

Diagnosing an OOM kill

Kernel and systemd logs identify the killed PostgreSQL process and report the postgresql service's oom-kill failure. Use these records to distinguish memory exhaustion from an ordinary query failure.

How PostgreSQL Mistakes and How to Avoid Them covers it

How deep it goes
Explains per-node, per-session, and parallel memory amplification, then stops short of a fixed sizing formula.
Examples
Uses PostgreSQL settings, pgbench concurrency tests, and kernel/systemd OOM logs.
What it assumes
Assumes PostgreSQL configuration and query-plan familiarity while explaining how memory multiplies across sessions and plan nodes.
What you can do after
Diagnose memory exhaustion from host logs and reduce risk through conservative, session-level work_mem settings.
How it connects
Connects work_mem, shared_buffers, parallel execution, temporary files, crash recovery, and failover.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of PostgreSQL Mistakes and How to Avoid Them. The section links point to the parts of the book it draws on.