]> git.ipfire.org Git - thirdparty/postgresql.git/commit
Fix OldestMemberMXactId and OldestVisibleMXactId array usage
authorHeikki Linnakangas <heikki.linnakangas@iki.fi>
Mon, 2 Mar 2026 17:19:22 +0000 (19:19 +0200)
committerHeikki Linnakangas <heikki.linnakangas@iki.fi>
Mon, 2 Mar 2026 17:19:22 +0000 (19:19 +0200)
commitccae90abdbb61b43b4cb0625f8677f1ad079c61c
tree169b762dd89770145da35e6ccd87e063409f0d92
parent344b572e3eff620ffc2e3680730103e33a502bc6
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 <y.sokolov@postgrespro.ru>
Reviewed-by: Sami Imseih <samimseih@gmail.com>
Reviewed-by: Chao Li <li.evan.chao@gmail.com>
Discussion: https://www.postgresql.org/message-id/7acc94b0-ea82-4657-b1b0-77842cb7a60c@postgrespro.ru
Backpatch-through: 17
src/backend/access/transam/multixact.c
src/backend/access/transam/twophase.c
src/backend/storage/lmgr/proc.c
src/include/storage/proc.h