Global memory or local memory? (was Re: work_mem) - Mailing list pgsql-admin

From Ron
Subject Global memory or local memory? (was Re: work_mem)
Date
Msg-id 852027d8-bc23-692e-8330-dc09d0f03af9@gmail.com
Whole thread Raw
In response to Re: work_mem  (MichaelDBA <MichaelDBA@sqlexec.com>)
Responses Re: Global memory or local memory? (was Re: work_mem)  ("David G. Johnston" <david.g.johnston@gmail.com>)
List 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.

pgsql-admin by date:

Previous
From: Bruce Momjian
Date:
Subject: Re: work_mem
Next
From: "David G. Johnston"
Date:
Subject: Re: Global memory or local memory? (was Re: work_mem)