[PG19] pg_upgrade from <= 18 loses the newest multixid if its members end at offset wraparound

From: Zsolt Parragi <zsolt(dot)parragi(at)percona(dot)com>
To: PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>, Heikki Linnakangas <hlinnaka(at)iki(dot)fi>
Subject: [PG19] pg_upgrade from <= 18 loses the newest multixid if its members end at offset wraparound
Date: 2026-10-15 19:27:36
Message-ID: CAN4CZFM8BCazGz6s1Vn5tMEXYiXE2fi8T2rwmwXSty5gD+h9rA@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hello

I/Claude found another corner case in the multixact offset conversion,
not covered by the issues in Noah's thread [1].

In 18 and below if the members of the newest multixid end exactly at
2^32 the shutdown checkpoint stores NextMultiOffset = 0, and the
server handles this scenario properly.

But PG19 after the upgrade doesn't:

select count(*) from t;
ERROR: MultiXact 1 has invalid offset
vacuum freeze t;
ERROR: MultiXact 1 has invalid offset
CONTEXT: while scanning block 0 offset 1 of relation "public.t"

pg_upgrade --check doesn't notice anything.

Reproducing it on an 18 cluster:

pg_resetwal -O 4294967294 old
# create the zeroed members segment for that offset (14078)
create table t(id int primary key, v int); insert into t values (1,0);
-- session 1
begin; select 1 from t where id = 1 for key share;
-- session 2
update t set v = 1 where id = 1;
-- session 1
commit;

then stop the server and upgrade it.

This needs the last multixid before the upgrade to end exactly at the
boundary, so it is definitely a corner case.

The attached patch moves the zero check into the branch that reads the
next multixid's slot, matching what the server does. The existing
length calculation already handles the wrap, since both offsets are
uint32.

It also adds a scenario to 007_multixact_conversion.pl (only runs with
oldinstall set to a pre-19 installation, like the wraparound one).

[1]: https://www.postgresql.org/message-id/20260827231757.78.noahmisch%40microsoft.com

Attachment Content-Type Size
v1-0001-pg_upgrade-Fix-last-multixid-ending-at-offset-wra.patch application/octet-stream 3.9 KB

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2026-10-15 19:34:03 Re: [PG19] psql backslash commands fail with translated messages and a non UTF-8 client encoding
Previous Message Peter Geoghegan 2026-10-15 19:12:19 Showing "Table Block Fetches" in EXPLAIN ANALYZE for index-only scans