Fix OldestMemberMXactId and OldestVisibleMXactId array usage Commit ab355e3a88 changed how the OldestMemberMXactId array is indexed. It's no longer indexed by synthetic dummyBackendId, but with ProcNumber. The PGPROC entries for prepared xacts come after auxiliary processes in the allProcs array, which rendered the calculation for MaxOldestSlot and the indexes into the array incorrect. (The OldestVisibleMXactId array is not used for prepared xacts, and thus never accessed with ProcNumber's greater than MaxBackends, so this only affects the OldestMemberMXactId array.)
As a result, a prepared xact would store its value past the end of the OldestMemberMXactId array, overflowing into the OldestVisibleMXactId array. That could cause a transaction's row lock to appear invisible to other backends, or other such visibility issues. With a very small max_connections setting, the store could even go beyond the OldestVisibleMXactId array, stomping over the first element in the BufferDescriptor array. To fix, calculate the array sizes more precisely, and introduce helper functions to calculate the array indexes correctly. Author: Yura Sokolov <[email protected]> Reviewed-by: Sami Imseih <[email protected]> Reviewed-by: Chao Li <[email protected]> Discussion: https://www.postgresql.org/message-id/[email protected] Backpatch-through: 17 Branch ------ REL_17_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/dcd9c06a4203cb5489bf1bd54f0a27db5d33cac4 Modified Files -------------- src/backend/access/transam/multixact.c | 131 +++++++++++++++++++++++---------- src/backend/access/transam/twophase.c | 7 +- src/backend/storage/lmgr/proc.c | 4 +- src/include/storage/proc.h | 2 + 4 files changed, 100 insertions(+), 44 deletions(-)
