| From: | Osama Abdul Qader <osamaabdulqaderpostgres(at)gmail(dot)com> |
|---|---|
| To: | Ajin Cherian <itsajin(at)gmail(dot)com> |
| Cc: | Zhijie Hou <houzhijie22(at)gmail(dot)com>, pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com> |
| Subject: | Re: Avoid using raw xmin of frozen tuples in logicalrep conflict detection |
| Date: | 2026-11-16 14:42:03 |
| Message-ID: | CAAprpiDzvQE=-c63X40kzsXmuBtCQMBh3FE2hCjHi0Ag2Oqv2Q@mail.gmail.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-hackers |
Hi there,
On Wed, 11 Nov 2026 at 08:09, Ajin Cherian <itsajin(at)gmail(dot)com> wrote:
> On Thu, Nov 5, 2026 at 12:05 AM Zhijie Hou <houzhijie22(at)gmail(dot)com> wrote:
> >
> > Hi,
> >
> >
> > Once a tuple is frozen, its raw t_xmin is retained only for debugging
> > purposes; its commit timestamp entry may no longer be valid, or the
> > 32-bit XID may have wrapped around and been reassigned in a later epoch.
> > Using the raw xmin of a frozen tuple could therefore trigger spurious
> > update_origin_differs or delete_origin_differs conflicts, or report
> > bogus transaction ID, origin, and commit timestamp details for unique
> > constraint conflicts.
> >
>
> I have a question about the basic premise here.
>
> As far as I can see, being frozen doesn't make the raw xmin wrong by
> itself. TransactionIdGetCommitTsData() already returns false when the
> xid falls outside [oldestCommitTsXid, newestCommitTsXid], so if
> commit_ts has been truncated past the xid, we just don't report a
> conflict, which is fine. Bogus data only comes back once the same
> 32-bit value has been reassigned and is back inside the commit_ts
> window, which needs on the order of 2^32 XIDs after the tuple was
> inserted. Until then, the raw xmin of a frozen tuple gives the correct
> origin and commit timestamp.
>
> With the patch, every frozen tuple is treated as having no xmin, so
> update_origin_differs / delete_origin_differs are never reported for
> it. When a tuple gets frozen depends on vacuum: vacuum_freeze_min_age,
> page-level opportunistic freezing since PG16, eager scanning of
> all-visible pages in PG18, or a manual VACUUM FREEZE. So for the same
> row and the same remote change, whether we report a genuine origin
> conflict would depend on whether autovacuum happened to freeze that
> page first, which makes it largely non-deterministic. That seems hard
> to explain to users, why the behaviour changes from case to case.
>
> The new test shows this. Rows (3,1) and (4,2) are inserted locally on
> node A and then frozen, and the subsequent UPDATE/DELETE come from B.
> The local origin (0) really does differ from B’s origin, so without
> VACUUM FREEZE these would be reported as update_origin_differs and
> delete_origin_differs, the mirror image of the delete_origin_differs
> case checked later in 035_conflicts.pl. The new test asserts that
> these real conflicts are no longer reported.
>
> So my question is whether being frozen is the right criterion, or
> whether we should try to address only the XID-reuse case. I don't
> immediately see a cheap way to tell a reused xid from the original
> with just 32 bits, so maybe the conservative behaviour is the price we
> have to pay.
>
> regards,
> Ajin Cherian
> Fujitsu Australia
>
>
>
Thanks for raising this. I think your concern about the behaviour becoming
dependent on vacuum timing is valid.
I agree that freezing does not necessarily make the original raw xmin
unusable. It changes how PostgreSQL interprets xmin for tuple visibility,
while the original XID remains stored in the tuple header. If that XID has
not been reused and its commit timestamp information is still available,
using it to retrieve the original transaction commit timestamp and
replication origin can still be legitimate.
I also agree that TransactionIdGetCommitTsData() cannot inherently
distinguish the original transaction from a later transaction that reused
the same 32-bit XID. Its commit-timestamp range check does not, by itself,
establish the identity of the transaction that originally inserted the
frozen tuple.
This leaves an important trade-off:
- Continuing to use raw xmin preserves origin-conflict detection while
the original transaction metadata remains valid, but risks attributing
metadata from a newer transaction after XID reuse.
- Treating every frozen tuple as having no usable xmin avoids that
stale-XID attribution, but can suppress genuine origin conflicts even when
the original metadata is still valid.
I think your observation about the regression test is particularly
important: the test currently verifies that conflicts disappear after VACUUM
FREEZE, but that alone does not establish that suppressing those conflicts
is the correct behaviour.
The current patch chooses the latter, but I think the resulting change in
conflict-detection behaviour deserves explicit justification.
Regards,
Osama Abdul Qader
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Matheus Alcantara | 2026-11-16 14:50:19 | Re: extension_control_path: ignore empty elements and deduplicate directories |
| Previous Message | Joao Rito | 2026-11-16 14:16:50 | Re: [PATCH v2] Avoid carrying self lock-only xmax to updated tuple |