| From: | Manu <manuelreyesbravo(at)gmail(dot)com> |
|---|---|
| To: | Saheed Ajiboye <ajiboyeca(at)gmail(dot)com> |
| Cc: | 253330017(at)nileuniversity(dot)edu(dot)ng, pgsql-hackers(at)lists(dot)postgresql(dot)org |
| Subject: | Re: Proposal: "query_work_mem" GUC, to distribute working memory to the query's individual operators |
| Date: | 2026-12-06 07:40:49 |
| Message-ID: | 179654284952.3432783.1367874171962852837@gmail.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-hackers |
Hi Saheed,
Yes, gladly. It is at
https://github.com/Manuelreyesbravo/pg_mem_governor, under the
PostgreSQL License, so you are free to use, modify and redistribute
it.
On Wed, Dec 2, 2026 at 10:19 PM Saheed Ajiboye <ajiboyeca(at)gmail(dot)com>
wrote:
> - run it on your v2 patch against PostgreSQL 19 and compare it with
> other allocation policies at equal budgets on TPC-H and JOB;
It needs a server with the v2 patch. The patch applies to master as
of today. On REL_19_STABLE one hunk fails, in nodeTableFuncscan.c,
because master has changed that spot since 19 branched (commit
a7f8cd811d6). That hunk only replaces work_mem with ExecGetWorkMem()
in the tuplestore_begin_heap() call; with that one line adjusted by
hand, the extension builds and its tests pass on 19.
> Could you share the pg_mem_governor source (a repository link or a
> tarball is fine), together with the spill-calibration scripts or data
> it uses, if those are separate?
The calibration is manual. mem_governor_calibrate() times a hash
join, a hashed aggregate and a sort on synthetic tables at a range of
work_mem sizes, one query at a time, and records how much each size
writes to temp files. It then recommends, per node kind, the smallest
size whose time is within a tolerance of the best one, after charging
the temp volume at a disk speed and concurrency you pass in;
mem_governor_recommend() redoes that step without measuring again. It
only returns the ALTER SYSTEM statements for the per-kind caps, and
applies nothing itself. So it assumes that temp files mostly stay in
the page cache while it measures, that spilling under load costs in
proportion to what is written, and that the synthetic queries stand
for the hash joins, aggregates and sorts of the real workload. The
scripts that ran it, and a benchmark with report and OLTP clients
sharing one budget, are in bench/, with the calibration data from one
machine.
> I'm currently measuring when Sort, Hash and HashAggregate nodes
> actually release their memory during execution, and I'll share the
> results here.
That is the part I'm most interested in. The governor holds a query's
grant until the executor state is freed, so a node that is done with
its memory keeps counting against the pool until the query ends. Your
measurements would show how much that costs, and I'd be glad to see
them in this thread.
Regards,
Manu
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Shlomi Noach | 2026-12-06 10:54:25 | Re: [PATCH] Fix timeline history after recovery stops on an ancestor |
| Previous Message | Pavel Stehule | 2026-12-06 07:21:58 | Re: extremely slow planner when DISTINCT clause holds more columns |