| From: | Chao Li <li(dot)evan(dot)chao(at)gmail(dot)com> |
|---|---|
| To: | Melanie Plageman <melanieplageman(at)gmail(dot)com> |
| Cc: | Alexander Lakhin <exclusion(at)gmail(dot)com>, Andres Freund <andres(at)anarazel(dot)de>, Tomas Vondra <tomas(at)vondra(dot)me>, David Rowley <dgrowleyml(at)gmail(dot)com>, Kirill Reshke <reshkekirill(at)gmail(dot)com>, Andrey Borodin <x4mmm(at)yandex-team(dot)ru>, Xuneng Zhou <xunengzhou(at)gmail(dot)com>, Robert Haas <robertmhaas(at)gmail(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>, Heikki Linnakangas <hlinnaka(at)iki(dot)fi> |
| Subject: | Re: eliminate xl_heap_visible to reduce WAL (and eventually set VM on-access) |
| Date: | 2026-09-14 02:22:10 |
| Message-ID: | E9CFFD7E-7B97-4850-84B0-6475BC5EEC7D@gmail.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-hackers |
> On Sep 12, 2026, at 04:08, Melanie Plageman <melanieplageman(at)gmail(dot)com> wrote:
>
> On Fri, Sep 11, 2026 at 1:24 PM Melanie Plageman
> <melanieplageman(at)gmail(dot)com> wrote:
>>
>> On Thu, Sep 10, 2026 at 3:25 PM Melanie Plageman
>> <melanieplageman(at)gmail(dot)com> wrote:
>>
>> Here is a patch for this. While writing it, I realized I do not
>> understand why we don't update the FSM when restoring an FPI --
>> especially for COPY FREEZE. The FSM won't be up-to-date after
>> promotion for those pages and vacuum won't scan them so they'll remain
>> that way forever. Obviously not something to change in backbranches,
>> but it strikes me as odd that we do that in any cases -- but
>> especially for COPY FREEZE.
>
> Correcting myself here: pre-19 COPY FREEZE relied on
> XLOG_HEAP2_VISIBLE records to update the FSM when the heap pages in
> the XLOG_HEAP2_MULTI_INSERT had heap page FPIs. But my question
> remains, what is the point of skipping FSM updates when there is a
> heap page FPI?
>
> On another note, an LLM found a bug in the commit in this series that
> set pd_prune_xid for multi-inserts. I set pd_prune_xid as long as the
> page wasn't being set all-frozen, but you can insert frozen tuples
> into a page when you are not then setting it all-frozen. In that case,
> you do not want to set pd_prune_xid. The worst that can happen is a
> spurious round of pruning for the page, but it's best to avoid this
> (and it wasn't the intent). Inserting a frozen tuple should not set a
> prune hint. Patch attached. Simple repro below:
>
> CREATE EXTENSION pageinspect;
> CREATE EXTENSION pg_visibility;
> BEGIN;
> CREATE TABLE t (id integer);
> COPY t FROM PROGRAM 'seq 1 3000' FREEZE;
> COMMIT;
> SELECT g AS blkno, (page_header(get_raw_page('t', g))).prune_xid,
> vm.all_visible, vm.all_frozen FROM generate_series( 0,
> pg_relation_size('t') / current_setting('block_size')::integer - 1) AS
> g JOIN pg_visibility_map('t') AS vm ON vm.blkno = g ORDER BY g;
>
> - Melanie
> <v1-0001-Avoid-setting-pd_prune_xid-when-inserting-frozen-.patch>
The change looks correct to me.
One nit: perhaps we could take this opportunity to do a small refactoring, such as declaring i in the for loop and moving tbuf, htup, and newlen into the loop. This would reduce their scope and may improve readability.
For your convenience, I made those small changes in v2. If you don’t like them, feel free to discard v2.
Best regards,
--
Chao Li (Evan)
HighGo Software Co., Ltd.
https://www.highgo.com/
| Attachment | Content-Type | Size |
|---|---|---|
| v2-0001-Avoid-setting-pd_prune_xid-when-inserting-frozen-.patch | application/octet-stream | 4.4 KB |
| From | Date | Subject | |
|---|---|---|---|
| Next Message | shihao zhong | 2026-09-14 02:35:00 | Re: REPACK (CONCURRENTLY) doesn't handle invalid indexes |
| Previous Message | Michael Paquier | 2026-09-14 02:21:51 | Re: pg_get_*_ddl() needs a redesign |