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.
