mxid and mxoff wraparound issues in pg_upgrade
Maxim Orlov <orlovmg@gmail.com>
From: Maxim Orlov <orlovmg@gmail.com>
To: Postgres hackers <pgsql-hackers@lists.postgresql.org>
Date: 2025-06-20T15:45:28Z
Lists: pgsql-hackers
Attachments
- v1-0001-Test-case-for-BUG-18863-and-BUG-18865.patch (application/octet-stream) patch v1-0001
- v1-0002-Fix-the-mxid-and-mxoff-wraparound-issues-in-pg_up.patch (application/octet-stream) patch v1-0002
Hi!
I've noticed two bugs reported [0] and [1] which are both related to the
wraparound of mxid and
mxoff. Problems for mxid and mxoff are minor, as they require hitting the
exact overflow limit to
occur. But it's better to correct it.
I included a test to reproduce the problem (see 0001). It is not intended
to be committed, I
guess. I then added a commit with a fix.
There two fixes.
1) pg_upgrade does not consider the mxid to be in a wraparound state. In
this case, I adjust
the mxid value to the FirstMultiXactId. Alternatively, it might be
conceivable to include the
ability to set InvalidMultiXactId in pg_resetwal, but this seems odd to
me.
2) pg_resetwall forbids to set mxoff to UINT_MAX32. I'm not sure if this
was done on
purpose or not, but perhaps this check can be removed.
Here is what I've got with the fix applied.
>>> before upgrade:
Latest checkpoint's NextMultiXactId: 0
Latest checkpoint's NextMultiOffset: 4294967295
Latest checkpoint's oldestMultiXid: 4294967295
>>> after upgrade:
Latest checkpoint's NextMultiXactId: 1
Latest checkpoint's NextMultiOffset: 4294967295
Latest checkpoint's oldestMultiXid: 4294967295
Thoughts?
[0]
https://www.postgresql.org/message-id/18863-72f08858855344a2%40postgresql.org
[1]
https://www.postgresql.org/message-id/18865-d4c66cf35c2a67af%40postgresql.org
--
Best regards,
Maxim Orlov.
Commits
Same data as JSON:
GET /api/v1/messages/:b64id/commits
the thread's linked commits as JSON, with link sources.
API reference →
-
Fix pg_upgrade around multixid and mxoff wraparound
- 97cd4b65af6c 15.16 landed
- e039b09f8d39 16.12 landed
- cb2ef0e92edb 17.8 landed
- 8747b969fd8b 18.2 landed
- 94939c5f3ab0 19 (unreleased) landed