From: Yuhang Qiu <iamqyh@gmail.com>
To: Jingtang Zhang <mrdrivingduck@gmail.com>
To: Peter Geoghegan <pg@bowt.ie>
To: Melanie Plageman <melanieplageman@gmail.com>
Cc: PostgreSQL-development <pgsql-hackers@postgresql.org>
Cc: pgsql-hackers@lists.postgresql.org
Subject: Re: Allow aggressive VACUUM to freeze without a cleanup lock
Date: Wed, 26 Aug 2026 07:34:34 +0800
Message-ID: <16EBC719-6DFC-4384-B4B9-F50349C9CCB9@gmail.com> (raw)
In-Reply-To: <CAH2-WzmP-g23iCemuQ=O0w_fvbyQps-rRjdBkkAmhBxOARSrXA@mail.gmail.com>
References: <CAPsk3_ATBnTeFo2NM6bHm82oNWrpEQDCL-08z6kNQ8MLbC0jrg@mail.gmail.com>
<CAAKRu_Z+ROEiBs3odEHbqatTs5Bk9TUdbmCXnveBScss-GEDng@mail.gmail.com>
<CAH2-Wz=VdXQ-yBcaXiS=PnT5Kf=wZ0f1YagFJUUZ0rFJAGtw6Q@mail.gmail.com>
<CAH2-WzmP-g23iCemuQ=O0w_fvbyQps-rRjdBkkAmhBxOARSrXA@mail.gmail.com>
Hi Melanie, Peter, Jingtang,
> So it's reasonable to surmise that freezing could be done with only an
> exclusive lock on top of the current VACUUM code (though not a shared
> lock, which seems really dangerous). And that page defragmentation is
> the only thing that necessitates a cleanup lock/makes this idea difficult.
Agreed. Freezing itself only needs an exclusive lock, a cleanup lock is needed
for page defragmentation. I also agree with Melanie that the patch should
explain this if it is not already documented elsewhere.
I reviewed the patch and found a few issues.
First, the buffer lock is released and reacquired between
`lazy_scan_noprune()` and `lazy_scan_freeze()`. The page may be changed or
already frozen during this window, so this assertion is not always valid:
```C
Assert(state.pagefrz.freeze_required);
```
Second, the code may call heap_prepare_freeze_tuple() and then discard the
freeze plans after finding an old DEAD tuple. This function may create a new
MultiXactId, write WAL, and advance the MultiXact state. These side effects
remain even if the plans are discarded.
There is also a small naming issue. lazy_scan_noprune and lazy_scan_freeze are
quite confusing now. I think lazy_scan_noprune is not correct at this moment.
The patch adds FreezeState, HeapPageFreezeParams, and
HeapPageFreezeResult, but they overlap with PruneState,
PruneFreezeParams, and PruneFreezeResult. These abstractions add complexity
without much reuse.
Pages containing old XIDs or MultiXactIds in DEAD tuples still need a cleanup
lock. I think this is a reasonable limitation for this patch.
Best Regards,
Yuhang Qiu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-hackers@postgresql.org
Cc: iamqyh@gmail.com, mrdrivingduck@gmail.com, pg@bowt.ie, melanieplageman@gmail.com
Subject: Re: Allow aggressive VACUUM to freeze without a cleanup lock
In-Reply-To: <16EBC719-6DFC-4384-B4B9-F50349C9CCB9@gmail.com>
References: <CAPsk3_ATBnTeFo2NM6bHm82oNWrpEQDCL-08z6kNQ8MLbC0jrg@mail.gmail.com> <CAAKRu_Z+ROEiBs3odEHbqatTs5Bk9TUdbmCXnveBScss-GEDng@mail.gmail.com> <CAH2-Wz=VdXQ-yBcaXiS=PnT5Kf=wZ0f1YagFJUUZ0rFJAGtw6Q@mail.gmail.com> <CAH2-WzmP-g23iCemuQ=O0w_fvbyQps-rRjdBkkAmhBxOARSrXA@mail.gmail.com> <16EBC719-6DFC-4384-B4B9-F50349C9CCB9@gmail.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
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