pg.ddx.io pgsql-hackers@postgresql.org mailing list archive
help / color / mirror / Atom feed[PATCH v1] Add vacuum_delay_point() to GiST empty-page deletion pass
6+ messages / 4 participants
[nested] [flat]
* [PATCH v1] Add vacuum_delay_point() to GiST empty-page deletion pass
@ 2026-07-21 10:02 Paul Kim <mok03127@gmail.com>
2026-07-21 12:11 ` Re: [PATCH v1] Add vacuum_delay_point() to GiST empty-page deletion pass Andrey Borodin <x4mmm@yandex-team.ru>
2026-07-27 19:25 ` Re: [PATCH v1] Add vacuum_delay_point() to GiST empty-page deletion pass solai v <solai.cdac@gmail.com>
0 siblings, 2 replies; 6+ messages in thread
From: Paul Kim @ 2026-07-21 10:02 UTC (permalink / raw)
To: pgsql-hackers@lists.postgresql.org
Hi,
While comparing the vacuum loops of the various index AMs I noticed that
gistvacuum_delete_empty_pages() -- the second pass of a GiST vacuum that
unlinks empty leaf pages -- does not call vacuum_delay_point(), even
though it reads a buffer and issues WAL-logged page deletions for every
internal page it revisits. The other page-scanning loops in
gistvacuum.c, gistvacuumscan() and the recursion in gistvacuumpage(),
both call it.
As a result this phase of a GiST vacuum ignores the cost-based vacuum
delay entirely, and only reacts to query cancellation when a buffer read
happens to perform I/O. On a large GiST index with many emptied leaf
pages this loop can end up walking every internal page of the index.
The attached patch adds a single vacuum_delay_point(false) at the top of
the loop, where no buffer lock is held, matching the sibling idiom. The
function has lacked the call since it was introduced in 7df159a620b.
This is long-standing rather than a recent regression, so I'll leave the
question of back-patching to a committer. Note that on branches before
18 vacuum_delay_point() takes no argument (the bool was added by
e5b0b0ce150), so a back-patch would drop the "false".
Thanks,
Paul Kim
Attachments:
v1-0001-Add-vacuum_delay_point-to-GiST-empty-page-deletio.patch (text/x-patch, 1.8K) download
From b611e157862cce7bd9b141427dcc30d8a26e5d6c Mon Sep 17 00:00:00 2001
From: Paul Kim <mok03127@gmail.com>
Date: Tue, 21 Jul 2026 18:30:41 +0900
Subject: [PATCH v1] Add vacuum_delay_point() to GiST empty-page deletion pass
gistvacuum_delete_empty_pages() rescans the index's internal pages to
unlink the empty leaf pages found during the main vacuum scan. For each
internal page it reads a buffer and may perform WAL-logged page
deletions, but the loop never calls vacuum_delay_point(). This phase of
a GiST vacuum therefore ignores the cost-based vacuum delay, unlike the
other page-scanning loops in this file: gistvacuumscan() calls
vacuum_delay_point() at the top of its per-page loop, and gistvacuumpage()
calls it before re-reading a buffer when it recurses to an earlier page.
Add vacuum_delay_point(false) at the top of the loop, where no buffer
lock is held, matching the sibling idiom. vacuum_delay_point() also
checks for interrupts, so this additionally lets the pass respond to
query cancellation without having to wait for a buffer read to perform
I/O.
gistvacuum_delete_empty_pages() has lacked this since it was introduced
in commit 7df159a620b.
---
src/backend/access/gist/gistvacuum.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/src/backend/access/gist/gistvacuum.c b/src/backend/access/gist/gistvacuum.c
index 686a0418054..6637b60d600 100644
--- a/src/backend/access/gist/gistvacuum.c
+++ b/src/backend/access/gist/gistvacuum.c
@@ -524,6 +524,9 @@ gistvacuum_delete_empty_pages(IndexVacuumInfo *info, GistVacState *vstate)
int ntodelete;
int deleted;
+ /* call vacuum_delay_point while not holding any buffer lock */
+ vacuum_delay_point(false);
+
buffer = ReadBufferExtended(rel, MAIN_FORKNUM, (BlockNumber) blkno,
RBM_NORMAL, info->strategy);
--
2.50.1 (Apple Git-155)
^ permalink raw reply [nested|flat] 6+ messages in thread
* Re: [PATCH v1] Add vacuum_delay_point() to GiST empty-page deletion pass
2026-07-21 10:02 [PATCH v1] Add vacuum_delay_point() to GiST empty-page deletion pass Paul Kim <mok03127@gmail.com>
@ 2026-07-21 12:11 ` Andrey Borodin <x4mmm@yandex-team.ru>
2026-07-21 22:35 ` Re: [PATCH v1] Add vacuum_delay_point() to GiST empty-page deletion pass Michael Paquier <michael@paquier.xyz>
1 sibling, 1 reply; 6+ messages in thread
From: Andrey Borodin @ 2026-07-21 12:11 UTC (permalink / raw)
To: Paul Kim <mok03127@gmail.com>; +Cc: pgsql-hackers mailing list <pgsql-hackers@lists.postgresql.org>
> On 21 Jul 2026, at 15:02, Paul Kim <mok03127@gmail.com> wrote:
>
> The attached patch adds a single vacuum_delay_point(false) at the top of
> the loop, where no buffer lock is held, matching the sibling idiom. The
> function has lacked the call since it was introduced in 7df159a620b.
Yup, this looks like an oversight.
>
> This is long-standing rather than a recent regression, so I'll leave the
> question of back-patching to a committer. Note that on branches before
> 18 vacuum_delay_point() takes no argument (the bool was added by
> e5b0b0ce150), so a back-patch would drop the "false".
I don't know whether we should back-patch this. But I think the decision
should be aligned with the similar one in your GIN thread [0].
Best regards, Andrey Borodin.
[0] https://www.postgresql.org/message-id/flat/178447127453.110.12276981925360691905%40mail.gmail.com
^ permalink raw reply [nested|flat] 6+ messages in thread
* Re: [PATCH v1] Add vacuum_delay_point() to GiST empty-page deletion pass
2026-07-21 10:02 [PATCH v1] Add vacuum_delay_point() to GiST empty-page deletion pass Paul Kim <mok03127@gmail.com>
2026-07-21 12:11 ` Re: [PATCH v1] Add vacuum_delay_point() to GiST empty-page deletion pass Andrey Borodin <x4mmm@yandex-team.ru>
@ 2026-07-21 22:35 ` Michael Paquier <michael@paquier.xyz>
2026-07-22 04:15 ` Re: Add vacuum_delay_point() to GiST empty-page deletion pass Paul Kim <mok03127@gmail.com>
0 siblings, 1 reply; 6+ messages in thread
From: Michael Paquier @ 2026-07-21 22:35 UTC (permalink / raw)
To: Andrey Borodin <x4mmm@yandex-team.ru>; +Cc: Paul Kim <mok03127@gmail.com>; pgsql-hackers mailing list <pgsql-hackers@lists.postgresql.org>; Heikki Linnakangas <hlinnaka@iki.fi>
On Tue, Jul 21, 2026 at 05:11:51PM +0500, Andrey Borodin wrote:
> On 21 Jul 2026, at 15:02, Paul Kim <mok03127@gmail.com> wrote:
>> This is long-standing rather than a recent regression, so I'll leave the
>> question of back-patching to a committer. Note that on branches before
>> 18 vacuum_delay_point() takes no argument (the bool was added by
>> e5b0b0ce150), so a back-patch would drop the "false".
>
> I don't know whether we should back-patch this. But I think the decision
> should be aligned with the similar one in your GIN thread [0].
Adding Heikki in CC as the committer of the change that removed
vacuum_delay_point() would attract his attention more easily. Done so
now.
I'd argue that this does not feel like a backpatch is strictly
required here. It took somebody 7 years to notice the gap, and I
suspect that some AI tool has been used for the scanning analysis.
--
Michael
Attachments:
signature.asc (application/pgp-signature, 832B) download
^ permalink raw reply [nested|flat] 6+ messages in thread
* Re: Add vacuum_delay_point() to GiST empty-page deletion pass
2026-07-21 10:02 [PATCH v1] Add vacuum_delay_point() to GiST empty-page deletion pass Paul Kim <mok03127@gmail.com>
2026-07-21 12:11 ` Re: [PATCH v1] Add vacuum_delay_point() to GiST empty-page deletion pass Andrey Borodin <x4mmm@yandex-team.ru>
2026-07-21 22:35 ` Re: [PATCH v1] Add vacuum_delay_point() to GiST empty-page deletion pass Michael Paquier <michael@paquier.xyz>
@ 2026-07-22 04:15 ` Paul Kim <mok03127@gmail.com>
0 siblings, 0 replies; 6+ messages in thread
From: Paul Kim @ 2026-07-22 04:15 UTC (permalink / raw)
To: pgsql-hackers@lists.postgresql.org; +Cc: michael@paquier.xyz, x4mmm@yandex-team.ru, heikki.linnakangas@iki.fi, Paul Kim <mok03127@gmail.com>
On 2026-07-21, Michael Paquier wrote:
> I'd argue that this does not feel like a backpatch is strictly
> required here. It took somebody 7 years to notice the gap [...]
Thanks, Michael -- and thanks, Andrey, for confirming the oversight.
Andrey, on aligning this with the GIN thread [0]: I think GiST is
actually a bit different. The GIN one is a regression -- the call was
there until fd83c83d094 dropped it in a deadlock fix -- so to me it
reads as a back-branch matter, given that on master your proposed
rework would replace that path and carry its own vacuum_delay_point().
This GiST pass, by contrast, has never had the call since 7df159a620b
introduced the two-pass deletion in 2019, and there's no comparable
rework in flight -- so it looks like a standalone master fix rather
than a back-patch.
I don't have a strong view either way, but master-only seems the
natural fit for GiST; I'll leave the final call to you, Heikki, and
Andrey.
[0] https://postgr.es/m/178447127453.110.12276981925360691905@mail.gmail.com
--
Paul Kim
^ permalink raw reply [nested|flat] 6+ messages in thread
* Re: [PATCH v1] Add vacuum_delay_point() to GiST empty-page deletion pass
2026-07-21 10:02 [PATCH v1] Add vacuum_delay_point() to GiST empty-page deletion pass Paul Kim <mok03127@gmail.com>
@ 2026-07-27 19:25 ` solai v <solai.cdac@gmail.com>
2026-09-01 18:57 ` Re: [PATCH v1] Add vacuum_delay_point() to GiST empty-page deletion pass Andrey Borodin <x4mmm@yandex-team.ru>
1 sibling, 1 reply; 6+ messages in thread
From: solai v @ 2026-07-27 19:25 UTC (permalink / raw)
To: Paul Kim <mok03127@gmail.com>; +Cc: pgsql-hackers@lists.postgresql.org
Hi all,
On Tue, Jul 28, 2026 at 12:16 AM Paul Kim <mok03127@gmail.com> wrote:
>
> Hi,
>
> While comparing the vacuum loops of the various index AMs I noticed that
> gistvacuum_delete_empty_pages() -- the second pass of a GiST vacuum that
> unlinks empty leaf pages -- does not call vacuum_delay_point(), even
> though it reads a buffer and issues WAL-logged page deletions for every
> internal page it revisits. The other page-scanning loops in
> gistvacuum.c, gistvacuumscan() and the recursion in gistvacuumpage(),
> both call it.
>
> As a result this phase of a GiST vacuum ignores the cost-based vacuum
> delay entirely, and only reacts to query cancellation when a buffer read
> happens to perform I/O. On a large GiST index with many emptied leaf
> pages this loop can end up walking every internal page of the index.
>
> The attached patch adds a single vacuum_delay_point(false) at the top of
> the loop, where no buffer lock is held, matching the sibling idiom. The
> function has lacked the call since it was introduced in 7df159a620b.
>
> This is long-standing rather than a recent regression, so I'll leave the
> question of back-patching to a committer. Note that on branches before
> 18 vacuum_delay_point() takes no argument (the bool was added by
> e5b0b0ce150), so a back-patch would drop the "false".
>
Thank you for the patch. I reviewed and tested the v1 patch. I was
able to reproduce the execution path by creating a large GiST index,
deleting most of the tuples to generate empty pages, and running
VACUUM (VERBOSE). The cleanup phase entered
gistvacuum_delete_empty_pages(), and with temporary instrumentation in
the function gistvacuum_delete_empty_pages() in gistvacuum.c. I
confirmed that the newly added vacuum_delay_point(false) is invoked
repeatedly while scanning internal pages.
VACUUM (VERBOSE) t;
index scan needed: 63058 pages from table (99.00% of total) had
9900000 dead item identifiers removed
index "gist_idx": pages: 54352 in total, 53224 newly deleted, 53224
currently deleted, 0 reusable
Logfile:
LOG: checkpoint starting: wal
LOG: Entered gistvacuum_delete_empty_pages
CONTEXT: while cleaning up index "gist_idx" of relation "public.t"
STATEMENT: VACUUM (VERBOSE) t;
LOG: Called vacuum_delay_point() in GiST empty-page deletion
The patch ensures that the empty-page deletion pass now periodically
invokes vacuum_delay_point(), making its behavior consistent with
other long-running VACUUM loops. I did not observe any functional
issues or regressions during testing. The patch looks good to me.
Regards,
Solai
^ permalink raw reply [nested|flat] 6+ messages in thread
* Re: [PATCH v1] Add vacuum_delay_point() to GiST empty-page deletion pass
2026-07-21 10:02 [PATCH v1] Add vacuum_delay_point() to GiST empty-page deletion pass Paul Kim <mok03127@gmail.com>
2026-07-27 19:25 ` Re: [PATCH v1] Add vacuum_delay_point() to GiST empty-page deletion pass solai v <solai.cdac@gmail.com>
@ 2026-09-01 18:57 ` Andrey Borodin <x4mmm@yandex-team.ru>
0 siblings, 0 replies; 6+ messages in thread
From: Andrey Borodin @ 2026-09-01 18:57 UTC (permalink / raw)
To: solai v <solai.cdac@gmail.com>; +Cc: Paul Kim <mok03127@gmail.com>; pgsql-hackers mailing list <pgsql-hackers@lists.postgresql.org>
> I did not observe any functional issues or regressions during testing.
> The patch looks good to me.
Solai, would you mark the CF entry Ready for Committer?
Best regards, Andrey Borodin.
[0] https://commitfest.postgresql.org/patch/7038/
^ permalink raw reply [nested|flat] 6+ messages in thread
end of thread, other threads:[~2026-09-01 18:57 UTC | newest]
Thread overview: 6+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2026-07-21 10:02 [PATCH v1] Add vacuum_delay_point() to GiST empty-page deletion pass Paul Kim <mok03127@gmail.com>
2026-07-21 12:11 ` Andrey Borodin <x4mmm@yandex-team.ru>
2026-07-21 22:35 ` Michael Paquier <michael@paquier.xyz>
2026-07-22 04:15 ` Paul Kim <mok03127@gmail.com>
2026-07-27 19:25 ` solai v <solai.cdac@gmail.com>
2026-09-01 18:57 ` Andrey Borodin <x4mmm@yandex-team.ru>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox