Postgres on a VM died overnight; `dmesg` shows "Out of memory: Killed process 2314 (postgres) total-vm:..., anon-rss:...".

IntermediateTroubleshootingDisk, memory and CPU
Answer

Likely causes → The kernel OOM killer picked Postgres because it was the biggest process when the box ran out of memory. Usual triggers: work_mem too high multiplied by many concurrent sorts, another process (a backup, a monitoring agent) eating RAM on the same VM, or no swap headroom.

Diagnose →

dmesg -T | grep -iE 'out of memory|killed process'
journalctl -k --since "-12h" | grep -i oom
grep -E 'shared_buffers|work_mem|max_connections' /etc/postgresql/*/main/postgresql.conf

Correlate the timestamp with cron jobs and the connection count.

Fix → Restart Postgres and check recovery finished cleanly. Lower work_mem or max_connections (put PgBouncer in front), and move the co-located memory hog elsewhere.

Prevent → Set vm.overcommit_memory=2 as the Postgres docs recommend for dedicated DB hosts, protect the postmaster with OOMScoreAdjust=-1000 in its systemd unit, and alert on available memory below 10%.

All Real-World Interview questions Roadmap: Interview readiness

More on Disk, memory and CPU