| From: | Alex Masterov <amasterov(at)gmail(dot)com> |
|---|---|
| To: | Andres Freund <andres(at)anarazel(dot)de> |
| Cc: | pgsql-hackers(at)postgresql(dot)org |
| Subject: | Re: Snapshot related assert failure on skink |
| Date: | 2026-11-20 08:25:49 |
| Message-ID: | CA+8z=zsmNnP3JYGBej3RJiSK4xQdcCOZ3EZkEuAUCrpMiTdFKA@mail.gmail.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-hackers |
Hi,
Commit 2817525f0 ("Fix rare assertion failure in standby, if primary
is restarted", discussed in "Snapshot related assert failure on
skink") made ExpireOldKnownAssignedTransactionIds() advance
latestCompletedXid and xactCompletionCount.
However, I can still trigger the assertion on standby through a
different path using only ordinary operations on any supported
postgres version, including v19rc2.
TRAP: failed Assert("TransactionIdPrecedesOrEquals(TransactionXmin,
RecentXmin)"), File: "procarray.c", Line: 2446, PID: 52757
LOG: client backend (PID 52757) was terminated by signal 6: Abort trap: 6
Mechanism
ProcArrayApplyRecoveryInfo() starts by calling
ExpireOldKnownAssignedTransactionIds(oldestRunningXid), which now
lifts latestCompletedXid to oldestRunningXid - 1.
If the standby is already STANDBY_SNAPSHOT_READY, the function then
returns early, without touching latestObservedXid. So
latestObservedXid can be left behind latestCompletedXid.
Then:
1. A standby backend takes a snapshot. Its xmin = xmax = the lifted
value (e.g., 931), and so TransactionXmin = 931.
2. The next WAL record with a real xid (931) reaches
RecordKnownAssignedTransactionIds(), which gap-fills KnownAssignedXids
from the old latestObservedXid + 1 (say 731) up to that xid.
3. The next snapshot taken in the same transaction (e.g., a catalog
snapshot) gets xmin 731 < TransactionXmin, and the assertion fires.
Reproduction
The attached pg_standby_xmin_repro.py needs only an install built with
--enable-cassert (no patches, no extensions). It sets up a primary
and a streaming standby, runs the steps above, then opens a REPEATABLE
READ transaction on the standby, creates a table on the primary (first
real xid), and queries it in the open standby transaction.
INST=/path/to/install python3 -I pg_standby_xmin_repro.py
Proposed fix
In the STANDBY_SNAPSHOT_READY early-return path of
ProcArrayApplyRecoveryInfo(), bring latestObservedXid up to
oldestRunningXid - 1 (the value just stored in latestCompletedXid) if
it is behind: extend SUBTRANS over the skipped xids and advance
nextXid past latestObservedXid, as the non-early path of that function
does. KnownAssignedXids is not touched.
Thanks,
Alexey Masterov
| Attachment | Content-Type | Size |
|---|---|---|
| pg_standby_xmin_repro.py | text/x-python-script | 9.0 KB |
| procarray_upstream_master.patch | application/octet-stream | 1.9 KB |
| From | Date | Subject | |
|---|---|---|---|
| Previous Message | Kyotaro Horiguchi | 2026-11-20 08:22:10 | Re: [PATCH v1] Preserve implicit composite casts in ROW deparsing |