Re: 64-bit MultiXactOffset vs. 9.3->9.4 upgrade, pg_resetwal, "wraparound" msg

Поиск
Список
Период
Сортировка
Искать

Re: 64-bit MultiXactOffset vs. 9.3->9.4 upgrade, pg_resetwal, "wraparound" msg

От:
Heikki Linnakangas <hlinnaka@iki.fi>
Дата:
On 28/08/2026 02:17, Noah Misch wrote:
> commit bd8d9c9 wrote:
>> Commit:     Heikki Linnakangas 
>> CommitDate: Tue Dec 9 13:53:03 2025 +0200
>>
>>      Widen MultiXactOffset to 64 bits
> 
>> --- a/src/bin/pg_upgrade/pg_upgrade.c
>> +++ b/src/bin/pg_upgrade/pg_upgrade.c
> 
>> +		nxtmulti = old_cluster.controldata.chkpnt_nxtmulti;
>> +		if (old_cluster.controldata.cat_ver >= MULTIXACT_FORMATCHANGE_CAT_VER)
>> +		{
>> +			/* Versions 9.3 - 18: convert all multixids  */
>> +			oldstMulti = old_cluster.controldata.chkpnt_oldstMulti;
> 
> If a cluster's upgrade history includes an upgrade from 9.3 to early 9.4, it
> may have a wrong value here.  Specifically, upgrades done before a61daa14
> (2014-07 commit) have that hazard.  We still have backend code to detect such
> cases and reduce damage:
> 
> 		ereport(LOG,
> 				(errmsg("cannot truncate up to MultiXact %u because it does not exist on disk, skipping truncation",
> 						newOldestMulti)));
> 
> However, the pg_upgrade side from the v19 commit lacks such protection.  If
> heap tuples still reference older multixacts than the faulty control data
> suggests, pg_upgrade will copy too small a range, making affected tuples
> unreadable.

Thanks, I'll look into this. My first reaction is that I think if 
oldstMulti is incorrectly too old, the upgrade will fail because the 
conversion routine will fail to find it. If it's too new, i.e. "in the 
future", it will also fail to find it.

The third possibility is that the bogus oldstMulti value is within the 
range of the "real" range. That can happen if multixid wraparound had 
already happened before the (broken) 9.3 -> 9.4 upgrade. In that case, 
even if the multixids are still readable on disk, you're one vacuum away 
from truncating them. In other words, the damage has already been done, 
or could be done at any minute. That's the scenario for which the commit 
message 78db307bb2 says "this mechanism cannot save us".

But I'll do some testing of that. Let's ensure that the error message 
makes sense at the very least.

> I also had Opus 4.8 look for defects in this change and write test cases.  It
> didn't find the above problem, but it had other findings.  I'm attaching the
> full report.  I recommend fixing at least these before release:
> 
>> +| 5 | `resetwal-nextmxoff-zero` | `src/bin/pg_resetwal/pg_resetwal.c:703`, and `-O` with no zero check at 297-307 | `pg_resetwal -f` (or `-O 0`) leaves `nextMultiOffset = 0`, the reserved "invalid offset"; first multixact created afterwards is permanently unreadable: `ERROR: MultiXact 1 has invalid offset` | Yes — `src/test/modules/test_slru/t/003_multixact_offset.pl` |

This was already fixed in commit 2cad308cb8.

>> +| 7 | `members-truncation-apparent-wraparound` | `src/backend/access/transam/multixact.c:2642-2647` | When `nextOffset` lands on a members page boundary, truncation logs `could not truncate directory "pg_multixact/members": apparent wraparound` (impossible for a 64-bit counter) and reclaims nothing | Yes — `003_multixact_offset.pl` |

Ok, I'll look into this one, and the other ones that might not be fixed yet.

- Heikki


Re: 64-bit MultiXactOffset vs. 9.3->9.4 upgrade, pg_resetwal, "wraparound" msg

От:
Heikki Linnakangas <hlinnaka@iki.fi>
Дата:
Вложения:
On 16/09/2026 14:33, Heikki Linnakangas wrote:
> On 28/08/2026 02:17, Noah Misch wrote:
>> commit bd8d9c9 wrote:
>>> Commit:     Heikki Linnakangas 
>>> CommitDate: Tue Dec 9 13:53:03 2025 +0200
>>>
>>>      Widen MultiXactOffset to 64 bits
>>
>>> --- a/src/bin/pg_upgrade/pg_upgrade.c
>>> +++ b/src/bin/pg_upgrade/pg_upgrade.c
>>
>>> +        nxtmulti = old_cluster.controldata.chkpnt_nxtmulti;
>>> +        if (old_cluster.controldata.cat_ver >= 
>>> MULTIXACT_FORMATCHANGE_CAT_VER)
>>> +        {
>>> +            /* Versions 9.3 - 18: convert all multixids  */
>>> +            oldstMulti = old_cluster.controldata.chkpnt_oldstMulti;
>>
>> If a cluster's upgrade history includes an upgrade from 9.3 to early 
>> 9.4, it
>> may have a wrong value here.  Specifically, upgrades done before a61daa14
>> (2014-07 commit) have that hazard.  We still have backend code to 
>> detect such
>> cases and reduce damage:
>>
>>         ereport(LOG,
>>                 (errmsg("cannot truncate up to MultiXact %u because it 
>> does not exist on disk, skipping truncation",
>>                         newOldestMulti)));
>>
>> However, the pg_upgrade side from the v19 commit lacks such 
>> protection.  If
>> heap tuples still reference older multixacts than the faulty control data
>> suggests, pg_upgrade will copy too small a range, making affected tuples
>> unreadable.
> 
> Thanks, I'll look into this. My first reaction is that I think if 
> oldstMulti is incorrectly too old, the upgrade will fail because the 
> conversion routine will fail to find it. If it's too new, i.e. "in the 
> future", it will also fail to find it.
> 
> The third possibility is that the bogus oldstMulti value is within the 
> range of the "real" range. That can happen if multixid wraparound had 
> already happened before the (broken) 9.3 -> 9.4 upgrade. In that case, 
> even if the multixids are still readable on disk, you're one vacuum away 
> from truncating them. In other words, the damage has already been done, 
> or could be done at any minute. That's the scenario for which the commit 
> message 78db307bb2 says "this mechanism cannot save us".
> 
> But I'll do some testing of that. Let's ensure that the error message 
> makes sense at the very least.

Ok, I reconstructed that scenario artificially with the attached script. 
It creates a new cluster, runs a test program to create a bunch of 
multixids, runs vacuum freeze to truncate the multixids SLRU and advance 
oldestMulti. Finally, it uses pg_resetwal to reset oldestMulti back to 
1, to simulate what you'd get with the buggy 9.3 pg_upgrade. I tested 
this with a v18 source cluster, but I don't think the source version 
matters. (It must've been pg_upgraded to 9.3 in the past, but it 
could've gone through more pg_upgrades since)

When you run pg_upgrade on that, it fails like this:

> Converting pg_multixact files                                 
> could not open file "/tmp/pgcluster/pg_multixact/offsets/0000": No such file or directory

Not an ideal error message, but at least you get an error rather than 
silently losing data.

With the attached patch, you get an error message crafted specifically 
for that case.

> Converting pg_multixact files                                 fatal
> 
> Segment file containing multixid 1 does not exist.
> This can happen if an old version of pg_upgrade was used in the past
> to upgrade the cluster from version 9.3 to 9.4. If that is the cause,
> it can be fixed by running VACUUM FREEZE before upgrade.
> Failure, exiting

I'm not sure this is worth committing though. How many clusters are 
there out there that have been pg_upgraded to version 9.3.0-9.3.4, and 
haven't since been running for long enough to fix the oldestMultiXid 
value? Having that error message seems pretty harmless too, but if you 
actually hit that case that the file is missing, it might actually be 
more likely that you've hit some other bug than that old pg_upgrade issue.

Another approach would be to ignore the oldestMulti in the control file 
and scan pg_multixact/offsets for the oldest segment that actually 
exists. But I don't like that. Unless you actually hit that old 
pg_upgrade bug, a missing file is a sign of trouble, and it's better 
that you get alerted about it than upgrading the broken cluster to a new 
version.

- Heikki

Re: 64-bit MultiXactOffset vs. 9.3->9.4 upgrade, pg_resetwal, "wraparound" msg

От:
Noah Misch <noah@leadboat.com>
Дата:
On Thu, Sep 17, 2026 at 06:25:58PM +0300, Heikki Linnakangas wrote:
> On 16/09/2026 14:33, Heikki Linnakangas wrote:
> > On 28/08/2026 02:17, Noah Misch wrote:
> > > commit bd8d9c9 wrote:
> > > > Commit:     Heikki Linnakangas 
> > > > CommitDate: Tue Dec 9 13:53:03 2025 +0200
> > > > 
> > > >      Widen MultiXactOffset to 64 bits
> > > 
> > > > --- a/src/bin/pg_upgrade/pg_upgrade.c
> > > > +++ b/src/bin/pg_upgrade/pg_upgrade.c
> > > 
> > > > +        nxtmulti = old_cluster.controldata.chkpnt_nxtmulti;
> > > > +        if (old_cluster.controldata.cat_ver >=
> > > > MULTIXACT_FORMATCHANGE_CAT_VER)
> > > > +        {
> > > > +            /* Versions 9.3 - 18: convert all multixids  */
> > > > +            oldstMulti = old_cluster.controldata.chkpnt_oldstMulti;
> > > 
> > > If a cluster's upgrade history includes an upgrade from 9.3 to early
> > > 9.4, it
> > > may have a wrong value here.  Specifically, upgrades done before a61daa14
> > > (2014-07 commit) have that hazard.  We still have backend code to
> > > detect such
> > > cases and reduce damage:
> > > 
> > >         ereport(LOG,
> > >                 (errmsg("cannot truncate up to MultiXact %u because
> > > it does not exist on disk, skipping truncation",
> > >                         newOldestMulti)));
> > > 
> > > However, the pg_upgrade side from the v19 commit lacks such
> > > protection.  If
> > > heap tuples still reference older multixacts than the faulty control data
> > > suggests, pg_upgrade will copy too small a range, making affected tuples
> > > unreadable.
> > 
> > Thanks, I'll look into this. My first reaction is that I think if
> > oldstMulti is incorrectly too old, the upgrade will fail because the
> > conversion routine will fail to find it. If it's too new, i.e. "in the
> > future", it will also fail to find it.

Agreed, those cases fail cleanly.  No concerns on those.

> > The third possibility is that the bogus oldstMulti value is within the
> > range of the "real" range.

That's the only scenario I felt was at risk.  For example, the range of MXIDs
in tuple headers is [(unsigned)-100M,200M], but oldestMulti is 1.

> > That can happen if multixid wraparound had
> > already happened before the (broken) 9.3 -> 9.4 upgrade. In that case,
> > even if the multixids are still readable on disk, you're one vacuum away
> > from truncating them. In other words, the damage has already been done,
> > or could be done at any minute.

Okay.  I briefly tried to verify how rapidly one can expect v18 to truncate
the SLRUs in this scenario, but I didn't get very far.  I will rely on your
analysis.  Thanks for studying it.

> With the attached patch, you get an error message crafted specifically for
> that case.
> 
> > Converting pg_multixact files                                 fatal
> > 
> > Segment file containing multixid 1 does not exist.
> > This can happen if an old version of pg_upgrade was used in the past
> > to upgrade the cluster from version 9.3 to 9.4. If that is the cause,
> > it can be fixed by running VACUUM FREEZE before upgrade.
> > Failure, exiting
> 
> I'm not sure this is worth committing though. How many clusters are there
> out there that have been pg_upgraded to version 9.3.0-9.3.4, and haven't
> since been running for long enough to fix the oldestMultiXid value? Having
> that error message seems pretty harmless too, but if you actually hit that
> case that the file is missing, it might actually be more likely that you've
> hit some other bug than that old pg_upgrade issue.

I wouldn't commit the more-specific error message.  If it did something for
the "third possibility", that might be different.  I think we can consider
closed the topic of how 9.3 upgrades interact with 64-bit MultiXactOffset.


Re: 64-bit MultiXactOffset vs. 9.3->9.4 upgrade, pg_resetwal, "wraparound" msg

От:
Heikki Linnakangas <hlinnaka@iki.fi>
Дата:
Вложения:
On 17/09/2026 19:21, Noah Misch wrote:
> On Thu, Sep 17, 2026 at 06:25:58PM +0300, Heikki Linnakangas wrote:
>> On 16/09/2026 14:33, Heikki Linnakangas wrote:
>>> On 28/08/2026 02:17, Noah Misch wrote:
>>>> commit bd8d9c9 wrote:
>>>>> Commit:     Heikki Linnakangas 
>>>>> CommitDate: Tue Dec 9 13:53:03 2025 +0200
>>>>>
>>>>>       Widen MultiXactOffset to 64 bits
>>>>
>>>>> --- a/src/bin/pg_upgrade/pg_upgrade.c
>>>>> +++ b/src/bin/pg_upgrade/pg_upgrade.c
>>>>
>>>>> +        nxtmulti = old_cluster.controldata.chkpnt_nxtmulti;
>>>>> +        if (old_cluster.controldata.cat_ver >=
>>>>> MULTIXACT_FORMATCHANGE_CAT_VER)
>>>>> +        {
>>>>> +            /* Versions 9.3 - 18: convert all multixids  */
>>>>> +            oldstMulti = old_cluster.controldata.chkpnt_oldstMulti;
>>>>
>>>> If a cluster's upgrade history includes an upgrade from 9.3 to early
>>>> 9.4, it
>>>> may have a wrong value here.  Specifically, upgrades done before a61daa14
>>>> (2014-07 commit) have that hazard.  We still have backend code to
>>>> detect such
>>>> cases and reduce damage:
>>>>
>>>>          ereport(LOG,
>>>>                  (errmsg("cannot truncate up to MultiXact %u because
>>>> it does not exist on disk, skipping truncation",
>>>>                          newOldestMulti)));
>>>>
>>>> However, the pg_upgrade side from the v19 commit lacks such
>>>> protection.  If
>>>> heap tuples still reference older multixacts than the faulty control data
>>>> suggests, pg_upgrade will copy too small a range, making affected tuples
>>>> unreadable.
>>>
>>> Thanks, I'll look into this. My first reaction is that I think if
>>> oldstMulti is incorrectly too old, the upgrade will fail because the
>>> conversion routine will fail to find it. If it's too new, i.e. "in the
>>> future", it will also fail to find it.
> 
> Agreed, those cases fail cleanly.  No concerns on those.
> 
>>> The third possibility is that the bogus oldstMulti value is within the
>>> range of the "real" range.
> 
> That's the only scenario I felt was at risk.  For example, the range of MXIDs
> in tuple headers is [(unsigned)-100M,200M], but oldestMulti is 1.
> 
>>> That can happen if multixid wraparound had
>>> already happened before the (broken) 9.3 -> 9.4 upgrade. In that case,
>>> even if the multixids are still readable on disk, you're one vacuum away
>>> from truncating them. In other words, the damage has already been done,
>>> or could be done at any minute.
> 
> Okay.  I briefly tried to verify how rapidly one can expect v18 to truncate
> the SLRUs in this scenario, but I didn't get very far.  I will rely on your
> analysis.  Thanks for studying it.

Thinking about this some more, you were right originally, there is 
danger here:

If you're in that situation, where oldestMulti is higher than 
min(datminmxid), VACUUM will _not_ truncate the slrus. That was the 
whole idea of commit 78db307bb2, to refrain from truncating. So you're 
not in much danger, unless you consume so many multixids that you start 
to overwrite the tail.

But v19 pg_upgrade would indeed effectively truncate them away, by not 
converting them to the new format.


A better fix here is to add a pre-check that oldestMulti < 
min(datminmxid). That seems like a good sanity check anyway, and it will 
catch that ancient 9.3 scenario.

Barring objections, I'll commit the attached to add that check. I didn't 
include a hint about that 9.3 upgrade bug, since I don't think you're 
very likely to hit that anymore. But it's good to have the check to 
prevent damage if you do manage to hit it, or some other bug.

- Heikki

Re: 64-bit MultiXactOffset vs. 9.3->9.4 upgrade, pg_resetwal, "wraparound" msg

От:
Noah Misch <noah@leadboat.com>
Дата:
On Fri, Sep 18, 2026 at 09:15:38PM +0300, Heikki Linnakangas wrote:
> From 866999c1251fbbde2f1d9db2799734c7c6e8fe54 Mon Sep 17 00:00:00 2001
> From: Heikki Linnakangas 
> Date: Fri, 18 Sep 2026 20:57:26 +0300
> Subject: [PATCH 1/1] Check that oldestXID and oldestMulti are consistent at
>  pg_upgrade

I read this patch.  It looks reasonable, and I expect it provides the intended
defense.  Thank you.


Re: 64-bit MultiXactOffset vs. 9.3->9.4 upgrade, pg_resetwal, "wraparound" msg

От:
Tom Lane <tgl@sss.pgh.pa.us>
Дата:
Noah Misch  writes:
> On Fri, Sep 18, 2026 at 09:15:38PM +0300, Heikki Linnakangas wrote:
>> From 866999c1251fbbde2f1d9db2799734c7c6e8fe54 Mon Sep 17 00:00:00 2001
>> From: Heikki Linnakangas 
>> Date: Fri, 18 Sep 2026 20:57:26 +0300
>> Subject: [PATCH 1/1] Check that oldestXID and oldestMulti are consistent at
>> pg_upgrade

> I read this patch.  It looks reasonable, and I expect it provides the intended
> defense.  Thank you.

The BF animals that run cross-version upgrade tests say that this
fails when upgrading from 9.2 [1]:

Performing Consistency Checks
-----------------------------
Checking cluster versions                                     ok
Checking database connection settings                         ok
Checking for unsupported encodings                            ok
Checking names of databases, roles, and tablespaces           ok
Checking database user is the install user                    ok
Checking for prepared transactions                            ok
Checking oldestXID and oldestMultiXid consistency             SQL command failed
SELECT datname, datfrozenxid, datminmxid FROM	pg_catalog.pg_database
ERROR:  column "datminmxid" does not exist
LINE 1: SELECT datname, datfrozenxid, datminmxid FROM pg_catalog.pg_...
                                      ^
Failure, exiting

Now, we've dropped support for upgrading from 9.2 in HEAD, but we
have not done so in v19, so I think this needs a fix in v19.
If nothing else works, we could just skip the whole check when source
server is <= 9.2.

(I don't think this is worth breaking beta4 release freeze for, but
it should get fixed afterwards.)

			regards, tom lane

[1] https://buildfarm.postgresql.org/cgi-bin/show_log.pl?nm=crake&dt=2026-09-19%2014%3A17%3A23


Re: 64-bit MultiXactOffset vs. 9.3->9.4 upgrade, pg_resetwal, "wraparound" msg

От:
Heikki Linnakangas <hlinnaka@iki.fi>
Дата:
Вложения:
On 20/09/2026 05:12, Tom Lane wrote:
> Noah Misch  writes:
>> On Fri, Sep 18, 2026 at 09:15:38PM +0300, Heikki Linnakangas wrote:
>>>  From 866999c1251fbbde2f1d9db2799734c7c6e8fe54 Mon Sep 17 00:00:00 2001
>>> From: Heikki Linnakangas 
>>> Date: Fri, 18 Sep 2026 20:57:26 +0300
>>> Subject: [PATCH 1/1] Check that oldestXID and oldestMulti are consistent at
>>> pg_upgrade
> 
>> I read this patch.  It looks reasonable, and I expect it provides the intended
>> defense.  Thank you.
> 
> The BF animals that run cross-version upgrade tests say that this
> fails when upgrading from 9.2 [1]:
> 
> Performing Consistency Checks
> -----------------------------
> Checking cluster versions                                     ok
> Checking database connection settings                         ok
> Checking for unsupported encodings                            ok
> Checking names of databases, roles, and tablespaces           ok
> Checking database user is the install user                    ok
> Checking for prepared transactions                            ok
> Checking oldestXID and oldestMultiXid consistency             SQL command failed
> SELECT datname, datfrozenxid, datminmxid FROM	pg_catalog.pg_database
> ERROR:  column "datminmxid" does not exist
> LINE 1: SELECT datname, datfrozenxid, datminmxid FROM pg_catalog.pg_...
>                                        ^
> Failure, exiting
> 
> Now, we've dropped support for upgrading from 9.2 in HEAD, but we
> have not done so in v19, so I think this needs a fix in v19.
> If nothing else works, we could just skip the whole check when source
> server is <= 9.2.

Ugh, that's what I get for not actually testing with a real 9.2 
installation..

Here's what I came up with for this. Thanks Andrew for also reporting 
this off-list; this is essentially what you proposed too.

> (I don't think this is worth breaking beta4 release freeze for, but
> it should get fixed afterwards.)

I'm actually inclined to push this now, I don't see much risk of causing 
more last-minute breakage. Isn't finding this kind of last-minute issues 
exactly the reason we have the freeze? But that's just a weak opinion, 
it also seems totally fine to me to leave this broken for beta4 and fix 
later.

- Heikki

Re: 64-bit MultiXactOffset vs. 9.3->9.4 upgrade, pg_resetwal, "wraparound" msg

От:
Andrew Dunstan <andrew@dunslane.net>
Дата:

On 2026-09-20 Su 8:59 AM, Heikki Linnakangas wrote:
>
>
> Here's what I came up with for this. Thanks Andrew for also reporting 
> this off-list; this is essentially what you proposed too.
>
>> (I don't think this is worth breaking beta4 release freeze for, but
>> it should get fixed afterwards.)
>
> I'm actually inclined to push this now, I don't see much risk of 
> causing more last-minute breakage. Isn't finding this kind of 
> last-minute issues exactly the reason we have the freeze? But that's 
> just a weak opinion, it also seems totally fine to me to leave this 
> broken for beta4 and fix later.
>
>

Hi Heikki,


Code freeze is over :-) Please push so the buildfarm can go green again.


cheers


andrew


--
Andrew Dunstan
EDB: https://www.enterprisedb.com



Re: 64-bit MultiXactOffset vs. 9.3->9.4 upgrade, pg_resetwal, "wraparound" msg

От:
Heikki Linnakangas <hlinnaka@iki.fi>
Дата:
On 23/09/2026 23:12, Andrew Dunstan wrote:
> On 2026-09-20 Su 8:59 AM, Heikki Linnakangas wrote:
>> Here's what I came up with for this. Thanks Andrew for also reporting 
>> this off-list; this is essentially what you proposed too.
>>
>>> (I don't think this is worth breaking beta4 release freeze for, but
>>> it should get fixed afterwards.)
>>
>> I'm actually inclined to push this now, I don't see much risk of 
>> causing more last-minute breakage. Isn't finding this kind of last- 
>> minute issues exactly the reason we have the freeze? But that's just a 
>> weak opinion, it also seems totally fine to me to leave this broken 
>> for beta4 and fix later.
> 
> Hi Heikki,
> 
> Code freeze is over :-) Please push so the buildfarm can go green again.

Pushed, thanks for the reminder!

- Heikki



FAQ