Re: [PATCH] pg_surgery: Fix WAL corruption from concurrent heap_force_kill

From: Melanie Plageman <melanieplageman(at)gmail(dot)com>
To: fabriziomello(at)gmail(dot)com
Cc: Zsolt Parragi <zsolt(dot)parragi(at)percona(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: [PATCH] pg_surgery: Fix WAL corruption from concurrent heap_force_kill
Date: 2026-05-06 23:54:36
Message-ID: CAAKRu_bvg17QhXopd1YcAX_MdGPzNXkQVTO1SvW8+2-6T2emJQ@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Wed, May 6, 2026 at 4:27 PM Fabrízio de Royes Mello
<fabriziomello(at)gmail(dot)com> wrote:
>
> On Tue, May 5, 2026 at 5:42 PM Zsolt Parragi <zsolt(dot)parragi(at)percona(dot)com> wrote:
> >
> > I verified both the patch, and that the test case catches the bug
> > without the patch, the overall change seems good to me.

I haven't reviewed the test, but I think heap_force_common() has
bigger problems than what your fix fixes. Definitely the lock on the
vmbuffer needs to be held not just while clearing the VM but also
while emitting WAL for those changes. But, actually, even more than
that, the changes to the heap and the accompanying changes to the VM
page should be logged in the same WAL record. It is forbidden for
PD_ALL_VISIBLE to be clear while the VM is set -- which is the state
we are in after replaying the WAL record clearing PD_ALL_VISIBLE
before replaying the one clearing the VM bits. You need all the
changes to happen atomically in one record.

This is briefly discussed as part of a larger bug fix I am working on
to correctly WAL log VM clears [1]. I propose a fix there that emits a
single WAL record for the heap and VM changes while holding a lock on
both pages.

- Melanie

[1] https://www.postgresql.org/message-id/flat/CAAKRu_Z_KAAZAHtuorifR2MRc_MkEcHf-C_t4b9HZaHpa3nriw%40mail.gmail.com#61d104a35fc95fa67708c060ec61d59b

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message jian he 2026-05-07 01:14:47 Re: FOR PORTION OF does not recompute GENERATED STORED columns that depend on the range column
Previous Message Tristan Partin 2026-05-06 23:26:42 Fix mismatched deallocation functions