Schedule - Nordic PGDay 2026

Beyond work_mem Myths: A Source‑Code‑Guided Tour Through PostgreSQL Memory Usage

Date: 2026-03-24
Time: 13:10–14:00
Room: Vision 2+3
Level: Intermediate

This talk is a source‑code‑guided investigation into how PostgreSQL actually allocates memory during query execution. It builds on my previous talk, “PostgreSQL Connections Memory Usage on Linux: How Much, Why, and When?”, presented at PostgreSQL Conference Germany 2025, which focused on practical measurements of PostgreSQL query memory usage based on aggregated data from Linux /proc/PID/smaps files. In this session, I trace memory usage for different types of queries, with the goal of eliminating speculation about work_mem and giving attendees a better understanding supported by both source‑code findings and practical measurements. We will also briefly revisit other aspects of PostgreSQL connection memory usage and explain why reported resident set size (RSS) numbers can look so huge compared to the memory actually consumed.

Key Takeaways - work_mem is only a soft limit — queries may use less, or far more, than the setting suggests - Real memory usage is much smaller than the giant RSS numbers you see in monitoring tools - Parallel query execution can multiply memory consumption in surprising ways - Visualizing memory usage over time reveals how PostgreSQL allocates and releases memory dynamically

Speaker

Josef Machytka