| From: | "Maksim(dot)Melnikov" <m(dot)melnikov(at)postgrespro(dot)ru> |
|---|---|
| To: | Andrey Borodin <x4mmm(at)yandex-team(dot)ru> |
| Cc: | Osama Abdul Qader <osamaabdulqader(dot)cs(at)gmail(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org> |
| Subject: | Re: Race between prepared transaction commit and checkpointer |
| Date: | 2026-09-11 10:09:42 |
| Message-ID: | 74ab901c-04ec-45b7-a6a6-d8ea7c606efa@postgrespro.ru |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-hackers |
On 9/11/26 11:33, Andrey Borodin wrote:
> Hi Maksim,
>
> On 11 Sep 2026, Maksim Melnikov wrote:
>> I am not sure but for example
>> it can be LookupGXact.
> Yes, your suspicion about LookupGXact() is correct. With your patch
> applied, I could still trigger its Assert(gxact->prepare_start_lsn) by
> pausing in the WAL branch and completing a checkpoint. Both holders
> use LW_SHARED, so the checkpoint can proceed. This was a direct call
> to the helper via a test wrapper, not an end-to-end logical replication
> test.
>
> I also reproduced the original race for both COMMIT PREPARED and
> ROLLBACK PREPARED. Your fix blocks that interleaving in both cases.
>
> Would it be better to take LW_EXCLUSIVE in CheckPointTwoPhase() and
> protect the state reads in both FinishPreparedTransaction() and
> LookupGXact() with LW_SHARED? That would address both readers without
> serializing their I/O under a global exclusive lock. The reader lock
> would still need to cover the WAL read, not just copying the LSN,
> because the checkpoint can otherwise proceed to recycling that WAL.
>
> Thank you!
>
>
> Best regards, Andrey Borodin.
>
>
>
Hi Andrey,
Yes, I agree that we should acquire LW_EXCLUSIVE in CheckPointTwoPhase,
also I agree that better to wrap I/O on FinishPreparedTransaction with
just LW_SHARED, but I have some doubts about LookupGXact bacause as I
see here we change gxact state and it seems better do it with EXCLUSIVE
lock. Maybe we should acquire LW_EXCLUSIVE in LookupGXact and release it
and then acquire LW_SHARED for I/O. What do you think? For you
convenience I've attached draft patch.
Thanks you.
Best regards
Maksim Melnikov
| Attachment | Content-Type | Size |
|---|---|---|
| v2-0001-Fixing-race-between-prepared-transaction-commit-a.patch | text/x-patch | 1.5 KB |
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Ashutosh Bapat | 2026-09-11 10:11:53 | Re: PGQ catalog representation and pg_dump support |
| Previous Message | Amit Langote | 2026-09-11 10:08:43 | Re: PG19: two RI fast-path issues found while testing the batching revert |