| From: | Andrey Borodin <x4mmm(at)yandex-team(dot)ru> |
|---|---|
| To: | Jacob Brazeal <jacob(dot)brazeal(at)gmail(dot)com> |
| Cc: | PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org> |
| Subject: | Re: serializable anomaly - duplicate primary keys |
| Date: | 2026-08-07 13:59:02 |
| Message-ID: | C2AF1055-2BF2-46B2-A64E-68481AF34C3F@yandex-team.ru |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-hackers |
> On 28 Jul 2026, at 10:36, Jacob Brazeal <jacob(dot)brazeal(at)gmail(dot)com> wrote:
>
> I found a SERIALIZABLE anomaly where a transaction reads a row, successfully
> inserts another row with the same primary key, observes both rows, and commits.
Hi Jacob,
Thanks for the report. I reproduced it, including with INSERT ... ON
CONFLICT DO NOTHING.
This is related to the ON CONFLICT issue discussed in [0], but has the
opposite ordering: here the deletion commits first, and the unique check
relies on it through SnapshotDirty.
The window seems fairly narrow: a serializable transaction must read a row,
keep its snapshot across another transaction's deletion, and then reuse the
same key. It does not corrupt the index or leave a persistent duplicate, but
the committed transaction violates the SERIALIZABLE guarantee. This seems
plausible in delete-and-recreate or upsert workflows with long transactions.
PFA invasive fix on top of HEAD. The table AM reports the deleting XID when
SnapshotDirty skips a tuple still visible to the transaction snapshot. SSI
then fails only if there is already an rw-conflict to that transaction. It
also marks the transaction doomed before raising the error, so a savepoint
cannot hide the failure.
This extends the table AM interface. An ABI-preserving back-branch fix can
be considered separately.
Best regards, Andrey Borodin.
[0] https://postgr.es/m/165342c0-0c75-461e-b334-b997639ad48d%40aphyr.com
| Attachment | Content-Type | Size |
|---|---|---|
| v1-0001-Detect-SSI-conflicts-when-unique-checks-reuse-keys.patch | application/octet-stream | 22.5 KB |
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Maksim.Melnikov | 2026-08-07 14:05:05 | Re: Init connection time grows quadratically |
| Previous Message | Alberto Piai | 2026-08-07 13:35:53 | Re: ALTER COLUMN SET EXPRESSION on partitions not work in case of constraint dependencies |