liveBook · Manning

Memory allocation

As explained in PostgreSQL Mistakes and How to Avoid Them

Memory allocation is the assignment of available memory resources to database processes and operations.

PostgreSQL memory settings can look generous yet become dangerous under concurrency. With shared_buffers = 12GB and work_mem = 2GB, a 100-client pgbench run produced roughly the same or slightly worse throughput, showing that larger values did not help. section 6.2

When per-query memory overwhelms the host

Increasing max_connections to 1000 made the stress test hang after 10 seconds. work_mem can allocate 2GB for each execution-plan node in each running query; many nodes, concurrent sessions, and parallel execution can quickly exceed available RAM. The Linux OOM killer may terminate PostgreSQL or another critical process. PostgreSQL then terminates other active backends and enters crash recovery. section 6.2

Safer operational guidance:

  • Size work_mem for realistic concurrent execution rather than treating it as a single global query allocation. section 6.2

How PostgreSQL Mistakes and How to Avoid Them covers it

How deep it goes
Explains shared_buffers, per-plan-node work_mem multiplication, concurrency, parallel execution, and OOM recovery consequences.
Examples
Uses 100-client and 1000-client pgbench runs, configuration listings, workload output, and Linux OOM logs.
What you can do after
Diagnose memory pressure with pgbench and system logs, then avoid allocating excessive work_mem.
How it connects
Connects memory allocation to work_mem, shared_buffers, execution plans, parallel execution, pgbench, and the OOM killer.

Also explained in

Compare how 11 books explain memory allocation →

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.