Re: Logical replication: lost updates/deletes and invalid log messages caused by SnapshotDirty + concurrent updates

From: Mihail Nikalayeu <mihailnikalayeu(at)gmail(dot)com>
To: PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, "manuelreyesbravo(at)gmail(dot)com" <manuelreyesbravo(at)gmail(dot)com>
Cc: Andres Freund <andres(at)anarazel(dot)de>
Subject: Re: Logical replication: lost updates/deletes and invalid log messages caused by SnapshotDirty + concurrent updates
Date: 2026-10-05 22:35:00
Message-ID: CADzfLwXHGGZ51FYwTwu_V25eVMEQpndtU-ccPg-_6AuQgt+QEw@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hello, everyone!

Manu reviewed the fix in the original thread [1] and pointed out a
behavior change. I'm replying here since this thread is about the
logical replication side.

The case is this: a local transaction inserts a row and remains open,
while an UPDATE for the same key arrives from the publisher. On
master, the dirty scan may see the uncommitted row, wait for the
inserter, and then apply the UPDATE after it commits. With the patch,
the row isn't visible, so we report update_missing immediately.

That behavior on master is racy, though. It only waits if the insert
has already made it into the index by the time the scan reaches it. If
the INSERT happens a little later, master reports update_missing as
well. In either case there is no committed row at the time the
replicated change is applied, which is different from the bug this
patch fixes, where the row exists throughout. I've updated the commit
message to make that distinction clear.

Manu also suggested doing another dirty scan when nothing is found, to
preserve the wait in more cases. That works, but it only makes the
race window smaller and reintroduces a dirty scan, so I left it out of
a fix intended to be back-patchable.

[1]: https://postgr.es/m/179010806896.909920.249094834696255448@gmail.com
Best regards,
Mikhail.

Attachment Content-Type Size
v20-0001-Find-tuples-to-update-or-delete-during-apply-usi.patch application/x-patch 23.1 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2026-10-05 22:35:58 Re: [PG19] plpgsql: SELECT INTO sets FOUND wrongly after a function becomes a SRF
Previous Message Michael Paquier 2026-10-05 22:32:19 Re: pg_resetwal: refuse to run when backup_label exists