How it works...
To know how much RAM a connection may use, we start with a baseline of 8 megabytes. This accounts for the library overhead, the likelihood of using a temporary tablespace, and other various allocations necessary for a session to function. To that, we add four times the work_mem setting. PostgreSQL allocates an instance of work_mem for each join, sort, merge, and several other operations necessary to execute a query.
Why four? Well, large and complex queries will use more, while short and simple queries will use less, so we start with something in the middle. It's actually possible that this multiplier is somewhat pessimistic, so it trends toward assuming higher memory use. That's fine, since overestimating, in this case, is ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access