Re: IPC/MultixactCreation on the Standby server

Ivan Bykov <i.bykov@modernsys.ru>

From: Ivan Bykov <i.bykov@modernsys.ru>
To: pgsql-hackers@lists.postgresql.org
Cc: Andrey Borodin <x4mmm@yandex-team.ru>
Date: 2025-11-24T08:20:00Z
Lists: pgsql-hackers
Hi!

It seems my previous email was sent only to Andrey directly and didn't pass moderation
because it had a patch attached. I've now resent it without patch another email address.

----
In GetNewMultiXactId() this code may lead to error
---
ExtendMultiXactOffset(MultiXactState->nextMXact + 1);
---
If MultiXactState->nextMXact = MaxMultiXactId (0xFFFFFFFF)
we will not extend MultiXactOffset as we should
---
ExtendMultiXactOffset(0);
   MultiXactIdToOffsetEntry(0)
        multi % MULTIXACT_OFFSETS_PER_PAGE  = 0
   return; /* skip SLRU extension */
---

Perhaps we should introduce a simple function to handle next MultiXact
calculation
---
static inline MultiXactId
NextMultiXactId(MultiXactId multi)
{
    return multi == MaxMultiXactId ? FirstMultiXactId : multi + 1;
}
---
I've attached a patch that fixes this issue, although it seems I've discovered 
another overflow bug in multixact_redo().
We might call:
---
multixact_redo()
   MultiXactAdvanceNextMXact(0xFFFFFFFF + 1, ...);
---
And if MultiXactState->nextMXact != InvalidMultiXactId (0), we will have 
MultiXactState->nextMXact = 0.
This appears to cause problems in code that assumes MultiXactState->nextMXact 
holds a valid MultiXactId.
For instance, in GetMultiXactId(), we would return an incorrect number 
of MultiXacts.

Although, spreading MultiXact overflow handling throughout multixact.c code 
seems error-prone. 
Maybe we should use a macro instead (which would also allow us to modify this
check and add compiler hints):

---
#define MultiXactAdjustOverflow(mxact) \
   if (unlikely((mxact) < FirstMultiXactId)) \
      mxact = FirstMultiXactId;
---

Commits

Same data as JSON: GET /api/v1/messages/:b64id/commits the thread's linked commits as JSON, with link sources. API reference →
  1. Fix test to work with non-8kB block sizes

  2. Fix setting next multixid's offset at offset wraparound

  3. Add test for multixid wraparound

  4. Set next multixid's offset when creating a new multixid

  5. psql: Improve tab completion for large objects.

  6. Refactor some repetitive SLRU code

  7. Transaction IDs wrap around, per my proposal of 13-Aug-01. More