Global memory or local memory? (was Re: work_mem)

From: Ron <ronljohnsonjr(at)gmail(dot)com>
To: pgsql-admin(at)lists(dot)postgresql(dot)org
Subject: Global memory or local memory? (was Re: work_mem)
Date: 2021-04-02 22:35:01
Message-ID: 852027d8-bc23-692e-8330-dc09d0f03af9@gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-admin

On 4/2/21 7:49 AM, MichaelDBA wrote:
> That is a common misconception.  It is not one work_mem buffer per SQL,
> but one work_mem buffer per required operation within that SQL.  So you
> can have manner work_mem buffers per SQL statement!
>
> Right from the official docs:
> work_mem sets the maximum amount of memory to be used by a query operation
> (such as a sort or hash table) before writing to temporary disk files. If
> this value is specified without units, it is taken as kilobytes...Note
> that for a complex query, several sort or hash operations might be running
> in parallel; each operation will be allowed to use as much memory as this
> value specifies before it starts to write data into temporary files. Also,
> several running sessions could be doing such operations concurrently.
> Therefore, the total memory used could be many times the value
> of|work_mem|; it is necessary to keep this fact in mind when choosing the
> value. Sort operations are used for|ORDER BY|,|DISTINCT|, and merge joins.
> Hash tables are used in hash joins, hash-based aggregation, and hash-based
> processing of|IN|subqueries.
>
> Regards,
> Michael Vitale

If multiple users are querying the same regions of the same tables, does
each process have to read the same blocks, or can they share ("oh look, some
other process has already read into memory some of the data blocks I need,
so I'll just share those buffers")?

--
Angular momentum makes the world go 'round.

In response to

Responses

Browse pgsql-admin by date

  From Date Subject
Next Message David G. Johnston 2021-04-02 22:58:06 Re: Global memory or local memory? (was Re: work_mem)
Previous Message Bruce Momjian 2021-04-02 15:34:36 Re: work_mem