summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorThomas Munro <tmunro@postgresql.org>2020-03-12 18:06:54 +1300
committerThomas Munro <tmunro@postgresql.org>2020-03-12 18:16:44 +1300
commit4e8cad2da36adff877c81d8c336d7c28ed19ebae (patch)
tree8e3f67a31ef5eb76ef4ce24c27b351d25322ae9a /src
parent2b9d70159154a5ff6eb2d6f09db6f8da433328aa (diff)
Fix nextXid tracking bug on standbys (9.5-11 only).
RecordKnownAssignedTransactionIds() should never move nextXid backwards. Before this commit, that could happen if some other code path had advanced it without advancing latestObservedXid. One consequence is that a well timed XLOG_CHECKPOINT_ONLINE could cause hot standby feedback messages to get confused and report an xmin from a future epoch, potentially allowing vacuum to run too soon on the primary. Repair, by making sure RecordKnownAssignedTransactionIds() can only move nextXid forwards. In release 12 and master, this was already done by commit 2fc7af5e, which consolidated similar code and straightened out this bug. Back-patch to supported releases before that. Author: Eka Palamadai <ekanatha@amazon.com> Discussion: https://postgr.es/m/98BB4805-D0A2-48E1-96F4-15014313EADC@amazon.com
Diffstat (limited to 'src')
-rw-r--r--src/backend/storage/ipc/procarray.c3
1 files changed, 2 insertions, 1 deletions
diff --git a/src/backend/storage/ipc/procarray.c b/src/backend/storage/ipc/procarray.c
index 166c3cf2f88..1bb87360463 100644
--- a/src/backend/storage/ipc/procarray.c
+++ b/src/backend/storage/ipc/procarray.c
@@ -3247,7 +3247,8 @@ RecordKnownAssignedTransactionIds(TransactionId xid)
next_expected_xid = latestObservedXid;
TransactionIdAdvance(next_expected_xid);
LWLockAcquire(XidGenLock, LW_EXCLUSIVE);
- ShmemVariableCache->nextXid = next_expected_xid;
+ if (TransactionIdFollows(next_expected_xid, ShmemVariableCache->nextXid))
+ ShmemVariableCache->nextXid = next_expected_xid;
LWLockRelease(XidGenLock);
}
}