Update TransactionXmin when MyProc->xmin is updated
authorHeikki Linnakangas <[email protected]>
Sat, 21 Dec 2024 21:42:39 +0000 (23:42 +0200)
committerHeikki Linnakangas <[email protected]>
Sat, 21 Dec 2024 21:42:39 +0000 (23:42 +0200)
GetSnapshotData() set TransactionXmin = MyProc->xmin, but when
SnapshotResetXmin() advanced MyProc->xmin, it did not advance
TransactionXmin correspondingly. That meant that TransactionXmin could
be older than MyProc->xmin, and XIDs between than TransactionXmin and
the real MyProc->xmin could be vacuumed away. One known consequence is
in pg_subtrans lookups: we might try to look up the status of an XID
that was already truncated away.

Back-patch to all supported versions.

Reviewed-by: Andres Freund
Discussion: https://www.postgresql.org/message-id/d27a046d-a1e4-47d1-a95c-fbabe41debb4@iki.fi

src/backend/utils/time/snapmgr.c

index e60360338d5750654f13093b0d5e10ddb26ecea1..e002d0c1368d22eb0929765c8059901c7d7ac50c 100644 (file)
@@ -875,7 +875,7 @@ SnapshotResetXmin(void)
 
    if (pairingheap_is_empty(&RegisteredSnapshots))
    {
-       MyProc->xmin = InvalidTransactionId;
+       MyProc->xmin = TransactionXmin = InvalidTransactionId;
        return;
    }
 
@@ -883,7 +883,7 @@ SnapshotResetXmin(void)
                                        pairingheap_first(&RegisteredSnapshots));
 
    if (TransactionIdPrecedes(MyProc->xmin, minSnapshot->xmin))
-       MyProc->xmin = minSnapshot->xmin;
+       MyProc->xmin = TransactionXmin = minSnapshot->xmin;
 }
 
 /*