pg.ddx.io  pgsql-hackers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
pg_upgrade silently truncates nextMultiOffset to 32 bits
9+ messages / 3 participants
[nested] [flat]

Commits from this thread:
  2026-08-27 4581767663 3fcb716719  Report next_multi_offset as bigint in pg_control_checkpoint().
  2026-08-27 058962fdc9 e721ce48dc  pg_upgrade: Read nextMultiOffset as a 64-bit value.
* pg_upgrade silently truncates nextMultiOffset to 32 bits
@ 2026-08-27 00:59 Masahiko Sawada <sawada.mshk@gmail.com>
  2026-08-27 07:06 ` Re: pg_upgrade silently truncates nextMultiOffset to 32 bits Chao Li <li.evan.chao@gmail.com>
  0 siblings, 1 reply; 9+ messages in thread

From: Masahiko Sawada @ 2026-08-27 00:59 UTC (permalink / raw)
  To: pgsql-hackers; +Cc: Heikki Linnakangas <heikki.linnakangas@iki.fi>

Hi all,
(CCing Heikki as the committer of commit bd8d9c9bdfa)

Commit bd8d9c9bdfa widened MultiXactOffset to uint64, but I found that
pg_upgrade still reads it as a uint32 value when reading the
pg_controldata continents:

else if ((p = strstr(bufin, "Latest checkpoint's NextMultiOffset:")) != NULL)
{
:
    p++;                /* remove ':' char */
    cluster->controldata.chkpnt_nxtmxoff = str2uint(p);

I think it should use strtou64() instead. The attached 0001 patch
fixes it. It introduces str2uint64() as other fields are read by a
similar helper function str2uint().

Also, when checking other similar codes around the new
MultiXactOffset, I found that pg_control_checkpoint() still reports
the value as an xid. I think we should report it as bigint instead.
What do you think? The attached 0002 patch fixes it.

Regards,

-- 
Masahiko Sawada
Amazon Web Services: https://aws.amazon.com

Attachments: download all (2 files, .tar.gz)

0002-Report-next_multi_offset-as-bigint-in-pg_control_che.patch (text/x-patch, 2.7K) download From 4389bc165db2ab33feab21e531bc6a1b7f3a546f Mon Sep 17 00:00:00 2001 From: Masahiko Sawada <sawada.mshk@gmail.com> Date: Wed, 26 Aug 2026 17:44:33 -0700 Subject: [PATCH 2/2] Report next_multi_offset as bigint in pg_control_checkpoint(). XXX Bump catalog version. Author: Reviewed-by: Discussion: https://postgr.es/m/ Backpatch-through: 19 --- doc/src/sgml/func/func-info.sgml | 2 +- src/backend/utils/misc/pg_controldata.c | 2 +- src/include/catalog/pg_proc.dat | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/doc/src/sgml/func/func-info.sgml b/doc/src/sgml/func/func-info.sgml index e3c05e8b933..2f03766b67a 100644 --- a/doc/src/sgml/func/func-info.sgml +++ b/doc/src/sgml/func/func-info.sgml @@ -3458,7 +3458,7 @@ acl | {postgres=arwdDxtm/postgres,foo=r/postgres} <row> <entry><structfield>next_multi_offset</structfield></entry> - <entry><type>xid</type></entry> + <entry><type>bigint</type></entry> </row> <row> diff --git a/src/backend/utils/misc/pg_controldata.c b/src/backend/utils/misc/pg_controldata.c index ab74d169c96..9014f0953e9 100644 --- a/src/backend/utils/misc/pg_controldata.c +++ b/src/backend/utils/misc/pg_controldata.c @@ -130,7 +130,7 @@ pg_control_checkpoint(PG_FUNCTION_ARGS) values[9] = TransactionIdGetDatum(ControlFile->checkPointCopy.nextMulti); nulls[9] = false; - values[10] = TransactionIdGetDatum(ControlFile->checkPointCopy.nextMultiOffset); + values[10] = Int64GetDatum(ControlFile->checkPointCopy.nextMultiOffset); nulls[10] = false; values[11] = TransactionIdGetDatum(ControlFile->checkPointCopy.oldestXid); diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat index f5867349d14..805a579080d 100644 --- a/src/include/catalog/pg_proc.dat +++ b/src/include/catalog/pg_proc.dat @@ -12346,7 +12346,7 @@ descr => 'pg_controldata checkpoint state information as a function', proname => 'pg_control_checkpoint', provolatile => 'v', prorettype => 'record', proargtypes => '', - proallargtypes => '{pg_lsn,pg_lsn,text,int4,int4,bool,bool,text,oid,xid,xid,xid,oid,xid,xid,oid,xid,xid,int4,timestamptz}', + proallargtypes => '{pg_lsn,pg_lsn,text,int4,int4,bool,bool,text,oid,xid,int8,xid,oid,xid,xid,oid,xid,xid,int4,timestamptz}', proargmodes => '{o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o}', proargnames => '{checkpoint_lsn,redo_lsn,redo_wal_file,timeline_id,prev_timeline_id,full_page_writes,logical_decoding,next_xid,next_oid,next_multixact_id,next_multi_offset,oldest_xid,oldest_xid_dbid,oldest_active_xid,oldest_multi_xid,oldest_multi_dbid,oldest_commit_ts_xid,newest_commit_ts_xid,data_page_checksum_version,checkpoint_time}', prosrc => 'pg_control_checkpoint' }, -- 2.55.0
0001-pg_upgrade-Read-nextMultiOffset-as-a-64-bit-value.patch (text/x-patch, 1.9K) download From 956b715e45e511b48d5d486f63b2f75968d5df90 Mon Sep 17 00:00:00 2001 From: Masahiko Sawada <sawada.mshk@gmail.com> Date: Wed, 26 Aug 2026 17:44:02 -0700 Subject: [PATCH 1/2] pg_upgrade: Read nextMultiOffset as a 64-bit value. Author: Reviewed-by: Discussion: https://postgr.es/m/ Backpatch-through: 19 --- src/bin/pg_upgrade/controldata.c | 2 +- src/bin/pg_upgrade/pg_upgrade.h | 1 + src/bin/pg_upgrade/util.c | 11 +++++++++++ 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/bin/pg_upgrade/controldata.c b/src/bin/pg_upgrade/controldata.c index fd772ba4f38..8c69329805b 100644 --- a/src/bin/pg_upgrade/controldata.c +++ b/src/bin/pg_upgrade/controldata.c @@ -352,7 +352,7 @@ get_control_data(ClusterInfo *cluster) pg_fatal("%d: controldata retrieval problem", __LINE__); p++; /* remove ':' char */ - cluster->controldata.chkpnt_nxtmxoff = str2uint(p); + cluster->controldata.chkpnt_nxtmxoff = str2uint64(p); got_mxoff = true; } else if ((p = strstr(bufin, "First log segment after reset:")) != NULL) diff --git a/src/bin/pg_upgrade/pg_upgrade.h b/src/bin/pg_upgrade/pg_upgrade.h index ccd1ac0d013..92607daace5 100644 --- a/src/bin/pg_upgrade/pg_upgrade.h +++ b/src/bin/pg_upgrade/pg_upgrade.h @@ -496,6 +496,7 @@ void cleanup_output_dirs(void); void prep_status(const char *fmt, ...) pg_attribute_printf(1, 2); void prep_status_progress(const char *fmt, ...) pg_attribute_printf(1, 2); unsigned int str2uint(const char *str); +uint64 str2uint64(const char *str); /* version.c */ diff --git a/src/bin/pg_upgrade/util.c b/src/bin/pg_upgrade/util.c index 08d6385b512..e7d7ab56445 100644 --- a/src/bin/pg_upgrade/util.c +++ b/src/bin/pg_upgrade/util.c @@ -353,3 +353,14 @@ str2uint(const char *str) { return strtoul(str, NULL, 10); } + +/* + * str2uint64() + * + * convert string to uint64 + */ +uint64 +str2uint64(const char *str) +{ + return strtou64(str, NULL, 10); +} -- 2.55.0
^ permalink raw reply [nested|flat] 9+ messages in thread

* Re: pg_upgrade silently truncates nextMultiOffset to 32 bits
  2026-08-27 00:59 pg_upgrade silently truncates nextMultiOffset to 32 bits Masahiko Sawada <sawada.mshk@gmail.com>
@ 2026-08-27 07:06 ` Chao Li <li.evan.chao@gmail.com>
  2026-08-27 07:35   ` Re: pg_upgrade silently truncates nextMultiOffset to 32 bits Masahiko Sawada <sawada.mshk@gmail.com>
  2026-08-27 08:01   ` Re: pg_upgrade silently truncates nextMultiOffset to 32 bits Heikki Linnakangas <hlinnaka@iki.fi>
  0 siblings, 2 replies; 9+ messages in thread

From: Chao Li @ 2026-08-27 07:06 UTC (permalink / raw)
  To: Masahiko Sawada <sawada.mshk@gmail.com>; +Cc: pgsql-hackers; Heikki Linnakangas <heikki.linnakangas@iki.fi>



> On Aug 27, 2026, at 08:59, Masahiko Sawada <sawada.mshk@gmail.com> wrote:
> 
> Hi all,
> (CCing Heikki as the committer of commit bd8d9c9bdfa)
> 
> Commit bd8d9c9bdfa widened MultiXactOffset to uint64, but I found that
> pg_upgrade still reads it as a uint32 value when reading the
> pg_controldata continents:
> 
> else if ((p = strstr(bufin, "Latest checkpoint's NextMultiOffset:")) != NULL)
> {
> :
>    p++;                /* remove ':' char */
>    cluster->controldata.chkpnt_nxtmxoff = str2uint(p);
> 
> I think it should use strtou64() instead. The attached 0001 patch
> fixes it. It introduces str2uint64() as other fields are read by a
> similar helper function str2uint().
> 
> Also, when checking other similar codes around the new
> MultiXactOffset, I found that pg_control_checkpoint() still reports
> the value as an xid. I think we should report it as bigint instead.
> What do you think? The attached 0002 patch fixes it.

bigint is a signed int64, so it cannot represent the full uint64 range, although perhaps this is only a theoretical concern. If we want to avoid this limitation, should we use numeric instead?

> 
> Regards,
> 
> -- 
> Masahiko Sawada
> Amazon Web Services: https://aws.amazon.com
> <0002-Report-next_multi_offset-as-bigint-in-pg_control_che.patch><0001-pg_upgrade-Read-nextMultiOffset-as-a-64-bit-value.patch>

Overall the patch looks good to me.

Best regards,
--
Chao Li (Evan)
HighGo Software Co., Ltd.
https://www.highgo.com/









^ permalink  raw  reply  [nested|flat] 9+ messages in thread

* Re: pg_upgrade silently truncates nextMultiOffset to 32 bits
  2026-08-27 00:59 pg_upgrade silently truncates nextMultiOffset to 32 bits Masahiko Sawada <sawada.mshk@gmail.com>
  2026-08-27 07:06 ` Re: pg_upgrade silently truncates nextMultiOffset to 32 bits Chao Li <li.evan.chao@gmail.com>
@ 2026-08-27 07:35   ` Masahiko Sawada <sawada.mshk@gmail.com>
  2026-08-27 08:20     ` Re: pg_upgrade silently truncates nextMultiOffset to 32 bits Heikki Linnakangas <hlinnaka@iki.fi>
  1 sibling, 1 reply; 9+ messages in thread

From: Masahiko Sawada @ 2026-08-27 07:35 UTC (permalink / raw)
  To: Chao Li <li.evan.chao@gmail.com>; +Cc: pgsql-hackers; Heikki Linnakangas <heikki.linnakangas@iki.fi>

On Thu, Aug 27, 2026 at 12:06 AM Chao Li <li.evan.chao@gmail.com> wrote:
>
>
>
> > On Aug 27, 2026, at 08:59, Masahiko Sawada <sawada.mshk@gmail.com> wrote:
> >
> > Hi all,
> > (CCing Heikki as the committer of commit bd8d9c9bdfa)
> >
> > Commit bd8d9c9bdfa widened MultiXactOffset to uint64, but I found that
> > pg_upgrade still reads it as a uint32 value when reading the
> > pg_controldata continents:
> >
> > else if ((p = strstr(bufin, "Latest checkpoint's NextMultiOffset:")) != NULL)
> > {
> > :
> >    p++;                /* remove ':' char */
> >    cluster->controldata.chkpnt_nxtmxoff = str2uint(p);
> >
> > I think it should use strtou64() instead. The attached 0001 patch
> > fixes it. It introduces str2uint64() as other fields are read by a
> > similar helper function str2uint().
> >
> > Also, when checking other similar codes around the new
> > MultiXactOffset, I found that pg_control_checkpoint() still reports
> > the value as an xid. I think we should report it as bigint instead.
> > What do you think? The attached 0002 patch fixes it.
>
> bigint is a signed int64, so it cannot represent the full uint64 range, although perhaps this is only a theoretical concern. If we want to avoid this limitation, should we use numeric instead?

I'd prefer to keep bigint here. pg_get_multixact_stats() already
reports num_members and members_size as int8, and both are derived
from these same offsets. Also, other fields in pg_control_checkpoint()
are fixed-width types, whereas numeric is pass-by-reference.

I considered using xid8 instead but it has only comparison operators
and no arithmetic, so we couldn't compute a delta between two
checkpoints.

Regards,

-- 
Masahiko Sawada
Amazon Web Services: https://aws.amazon.com






^ permalink  raw  reply  [nested|flat] 9+ messages in thread

* Re: pg_upgrade silently truncates nextMultiOffset to 32 bits
  2026-08-27 00:59 pg_upgrade silently truncates nextMultiOffset to 32 bits Masahiko Sawada <sawada.mshk@gmail.com>
  2026-08-27 07:06 ` Re: pg_upgrade silently truncates nextMultiOffset to 32 bits Chao Li <li.evan.chao@gmail.com>
  2026-08-27 07:35   ` Re: pg_upgrade silently truncates nextMultiOffset to 32 bits Masahiko Sawada <sawada.mshk@gmail.com>
@ 2026-08-27 08:20     ` Heikki Linnakangas <hlinnaka@iki.fi>
  2026-08-27 08:58       ` Re: pg_upgrade silently truncates nextMultiOffset to 32 bits Heikki Linnakangas <hlinnaka@iki.fi>
  0 siblings, 1 reply; 9+ messages in thread

From: Heikki Linnakangas @ 2026-08-27 08:20 UTC (permalink / raw)
  To: Masahiko Sawada <sawada.mshk@gmail.com>; Chao Li <li.evan.chao@gmail.com>; +Cc: pgsql-hackers; Heikki Linnakangas <heikki.linnakangas@iki.fi>

Sorry, I missed this reply of yours earlier.

On 27/08/2026 10:35, Masahiko Sawada wrote:
> On Thu, Aug 27, 2026 at 12:06 AM Chao Li <li.evan.chao@gmail.com> wrote:
>> bigint is a signed int64, so it cannot represent the full uint64 range, although perhaps this is only a theoretical concern. If we want to avoid this limitation, should we use numeric instead?
> 
> I'd prefer to keep bigint here. pg_get_multixact_stats() already
> reports num_members and members_size as int8, and both are derived
> from these same offsets. Also, other fields in pg_control_checkpoint()
> are fixed-width types, whereas numeric is pass-by-reference.
> 
> I considered using xid8 instead but it has only comparison operators
> and no arithmetic, so we couldn't compute a delta between two
> checkpoints.

Hmm, that's a good point, although 'xid' didn't have those operators or 
arithmetic either.

- Heikki







^ permalink  raw  reply  [nested|flat] 9+ messages in thread

* Re: pg_upgrade silently truncates nextMultiOffset to 32 bits
  2026-08-27 00:59 pg_upgrade silently truncates nextMultiOffset to 32 bits Masahiko Sawada <sawada.mshk@gmail.com>
  2026-08-27 07:06 ` Re: pg_upgrade silently truncates nextMultiOffset to 32 bits Chao Li <li.evan.chao@gmail.com>
  2026-08-27 07:35   ` Re: pg_upgrade silently truncates nextMultiOffset to 32 bits Masahiko Sawada <sawada.mshk@gmail.com>
  2026-08-27 08:20     ` Re: pg_upgrade silently truncates nextMultiOffset to 32 bits Heikki Linnakangas <hlinnaka@iki.fi>
@ 2026-08-27 08:58       ` Heikki Linnakangas <hlinnaka@iki.fi>
  2026-08-27 17:25         ` Re: pg_upgrade silently truncates nextMultiOffset to 32 bits Masahiko Sawada <sawada.mshk@gmail.com>
  0 siblings, 1 reply; 9+ messages in thread

From: Heikki Linnakangas @ 2026-08-27 08:58 UTC (permalink / raw)
  To: Masahiko Sawada <sawada.mshk@gmail.com>; Chao Li <li.evan.chao@gmail.com>; +Cc: pgsql-hackers

On 27/08/2026 11:20, Heikki Linnakangas wrote:
> Sorry, I missed this reply of yours earlier.
> 
> On 27/08/2026 10:35, Masahiko Sawada wrote:
>> On Thu, Aug 27, 2026 at 12:06 AM Chao Li <li.evan.chao@gmail.com> wrote:
>>> bigint is a signed int64, so it cannot represent the full uint64 
>>> range, although perhaps this is only a theoretical concern. If we 
>>> want to avoid this limitation, should we use numeric instead?
>>
>> I'd prefer to keep bigint here. pg_get_multixact_stats() already
>> reports num_members and members_size as int8, and both are derived
>> from these same offsets. Also, other fields in pg_control_checkpoint()
>> are fixed-width types, whereas numeric is pass-by-reference.
>>
>> I considered using xid8 instead but it has only comparison operators
>> and no arithmetic, so we couldn't compute a delta between two
>> checkpoints.
> 
> Hmm, that's a good point, although 'xid' didn't have those operators or 
> arithmetic either.

That was inaccurate: both 'xid' and 'xid8' do have comparison operators. 
But they don't have a "minus" or "diff" operator, so you indeed cannot 
easily do "b - a".

I don't have a strong opinion, I'm happy with either bigint or xid8 
here. Bigint is probably more convenient in practice, and it's good to 
not confuse mxact offsets with transaction ids by abusing the xid8 type. 
Then again, it was 'xid' before, which had the same issues and we went 
with 'xid' anyway. Then again, now that it doesn't wrap around anymore, 
maybe 'bigint' makes more sense now.

Would you like to decide and commit this, or would you prefer me to do it?

- Heikki







^ permalink  raw  reply  [nested|flat] 9+ messages in thread

* Re: pg_upgrade silently truncates nextMultiOffset to 32 bits
  2026-08-27 00:59 pg_upgrade silently truncates nextMultiOffset to 32 bits Masahiko Sawada <sawada.mshk@gmail.com>
  2026-08-27 07:06 ` Re: pg_upgrade silently truncates nextMultiOffset to 32 bits Chao Li <li.evan.chao@gmail.com>
  2026-08-27 07:35   ` Re: pg_upgrade silently truncates nextMultiOffset to 32 bits Masahiko Sawada <sawada.mshk@gmail.com>
  2026-08-27 08:20     ` Re: pg_upgrade silently truncates nextMultiOffset to 32 bits Heikki Linnakangas <hlinnaka@iki.fi>
  2026-08-27 08:58       ` Re: pg_upgrade silently truncates nextMultiOffset to 32 bits Heikki Linnakangas <hlinnaka@iki.fi>
@ 2026-08-27 17:25         ` Masahiko Sawada <sawada.mshk@gmail.com>
  2026-08-27 17:56           ` Re: pg_upgrade silently truncates nextMultiOffset to 32 bits Heikki Linnakangas <hlinnaka@iki.fi>
  0 siblings, 1 reply; 9+ messages in thread

From: Masahiko Sawada @ 2026-08-27 17:25 UTC (permalink / raw)
  To: Heikki Linnakangas <hlinnaka@iki.fi>; +Cc: Chao Li <li.evan.chao@gmail.com>; pgsql-hackers

On Thu, Aug 27, 2026 at 1:58 AM Heikki Linnakangas <hlinnaka@iki.fi> wrote:
>
> On 27/08/2026 11:20, Heikki Linnakangas wrote:
> > Sorry, I missed this reply of yours earlier.
> >
> > On 27/08/2026 10:35, Masahiko Sawada wrote:
> >> On Thu, Aug 27, 2026 at 12:06 AM Chao Li <li.evan.chao@gmail.com> wrote:
> >>> bigint is a signed int64, so it cannot represent the full uint64
> >>> range, although perhaps this is only a theoretical concern. If we
> >>> want to avoid this limitation, should we use numeric instead?
> >>
> >> I'd prefer to keep bigint here. pg_get_multixact_stats() already
> >> reports num_members and members_size as int8, and both are derived
> >> from these same offsets. Also, other fields in pg_control_checkpoint()
> >> are fixed-width types, whereas numeric is pass-by-reference.
> >>
> >> I considered using xid8 instead but it has only comparison operators
> >> and no arithmetic, so we couldn't compute a delta between two
> >> checkpoints.
> >
> > Hmm, that's a good point, although 'xid' didn't have those operators or
> > arithmetic either.
>
> That was inaccurate: both 'xid' and 'xid8' do have comparison operators.
> But they don't have a "minus" or "diff" operator, so you indeed cannot
> easily do "b - a".
>
> I don't have a strong opinion, I'm happy with either bigint or xid8
> here. Bigint is probably more convenient in practice, and it's good to
> not confuse mxact offsets with transaction ids by abusing the xid8 type.
> Then again, it was 'xid' before, which had the same issues and we went
> with 'xid' anyway. Then again, now that it doesn't wrap around anymore,
> maybe 'bigint' makes more sense now.

I missed the point that we used to use 'xid' for that field. But I
agree that 'bigint' makes more sense.

> Would you like to decide and commit this, or would you prefer me to do it?

I'm going to take them and go with the 'bigint' column if you're okay.

I've added the commit messages to the patches.


Regards,

--
Masahiko Sawada
Amazon Web Services: https://aws.amazon.com

Attachments: download all (2 files, .tar.gz)

v2-0001-pg_upgrade-Read-nextMultiOffset-as-a-64-bit-value.patch (application/x-patch, 2.5K) download From 3053fd1381b36d4a28ad05e773148d21d80a25b8 Mon Sep 17 00:00:00 2001 From: Masahiko Sawada <sawada.mshk@gmail.com> Date: Wed, 26 Aug 2026 17:44:02 -0700 Subject: [PATCH v2 1/3] pg_upgrade: Read nextMultiOffset as a 64-bit value. Commit bd8d9c9bdfa widened MultiXactOffset to 64 bits and widened ControlData.chkpnt_nxtmxoff accordingly, but get_control_data() still read the "Latest checkpoint's NextMultiOffset" line with str2uint(), which returns unsigned int. This commit adds str2uint64(), mirroring the str2uint() helper used for the other control file fields, and reads the offset with it. Backpatch to v19, where MultiXactOffset was widened. Reviewed-by: Heikki Linnakangas <hlinnaka@iki.fi> Reviewed-by: Chao Li <li.evan.chao@gmail.com> Discussion: https://postgr.es/m/CAD21AoCvzerscfU8o4ARQ793yAGHpQ72r2x5apeC_W2-k=SLCQ@mail.gmail.com Backpatch-through: 19 --- src/bin/pg_upgrade/controldata.c | 2 +- src/bin/pg_upgrade/pg_upgrade.h | 1 + src/bin/pg_upgrade/util.c | 11 +++++++++++ 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/bin/pg_upgrade/controldata.c b/src/bin/pg_upgrade/controldata.c index fd772ba4f38..8c69329805b 100644 --- a/src/bin/pg_upgrade/controldata.c +++ b/src/bin/pg_upgrade/controldata.c @@ -352,7 +352,7 @@ get_control_data(ClusterInfo *cluster) pg_fatal("%d: controldata retrieval problem", __LINE__); p++; /* remove ':' char */ - cluster->controldata.chkpnt_nxtmxoff = str2uint(p); + cluster->controldata.chkpnt_nxtmxoff = str2uint64(p); got_mxoff = true; } else if ((p = strstr(bufin, "First log segment after reset:")) != NULL) diff --git a/src/bin/pg_upgrade/pg_upgrade.h b/src/bin/pg_upgrade/pg_upgrade.h index ccd1ac0d013..92607daace5 100644 --- a/src/bin/pg_upgrade/pg_upgrade.h +++ b/src/bin/pg_upgrade/pg_upgrade.h @@ -496,6 +496,7 @@ void cleanup_output_dirs(void); void prep_status(const char *fmt, ...) pg_attribute_printf(1, 2); void prep_status_progress(const char *fmt, ...) pg_attribute_printf(1, 2); unsigned int str2uint(const char *str); +uint64 str2uint64(const char *str); /* version.c */ diff --git a/src/bin/pg_upgrade/util.c b/src/bin/pg_upgrade/util.c index 08d6385b512..e7d7ab56445 100644 --- a/src/bin/pg_upgrade/util.c +++ b/src/bin/pg_upgrade/util.c @@ -353,3 +353,14 @@ str2uint(const char *str) { return strtoul(str, NULL, 10); } + +/* + * str2uint64() + * + * convert string to uint64 + */ +uint64 +str2uint64(const char *str) +{ + return strtou64(str, NULL, 10); +} -- 2.55.0
v2-0002-Report-next_multi_offset-as-bigint-in-pg_control_.patch (application/x-patch, 3.4K) download From 7cf04d9bddb4eaa8592f2e5b050b24dd97f5f4be Mon Sep 17 00:00:00 2001 From: Masahiko Sawada <sawada.mshk@gmail.com> Date: Wed, 26 Aug 2026 17:44:33 -0700 Subject: [PATCH v2 2/3] Report next_multi_offset as bigint in pg_control_checkpoint(). Commit bd8d9c9bdfa widened MultiXactOffset to 64 bits, but pg_control_checkpoint() still handle checkPointCopy.nextMultiOffset as xid type and declared next_multi_offset column as xid. Since xid is 32 bits wide, an offset above 2^32 was reported truncated, while pg_controldata printed the full value of the same field. This commit reports the column as bigint instead. That matches pg_get_multixact_stats(), which already reports num_members and members_size, both derived from these same offsets, as int8. Backpatch to v19, where MultiXactOffset was widened. Bump catalog version. Reviewed-by: Heikki Linnakangas <hlinnaka@iki.fi> Reviewed-by: Chao Li <li.evan.chao@gmail.com> Discussion: https://postgr.es/m/CAD21AoCvzerscfU8o4ARQ793yAGHpQ72r2x5apeC_W2-k=SLCQ@mail.gmail.com Backpatch-through: 19 --- doc/src/sgml/func/func-info.sgml | 2 +- src/backend/utils/misc/pg_controldata.c | 2 +- src/include/catalog/pg_proc.dat | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/doc/src/sgml/func/func-info.sgml b/doc/src/sgml/func/func-info.sgml index e3c05e8b933..2f03766b67a 100644 --- a/doc/src/sgml/func/func-info.sgml +++ b/doc/src/sgml/func/func-info.sgml @@ -3458,7 +3458,7 @@ acl | {postgres=arwdDxtm/postgres,foo=r/postgres} <row> <entry><structfield>next_multi_offset</structfield></entry> - <entry><type>xid</type></entry> + <entry><type>bigint</type></entry> </row> <row> diff --git a/src/backend/utils/misc/pg_controldata.c b/src/backend/utils/misc/pg_controldata.c index ab74d169c96..9014f0953e9 100644 --- a/src/backend/utils/misc/pg_controldata.c +++ b/src/backend/utils/misc/pg_controldata.c @@ -130,7 +130,7 @@ pg_control_checkpoint(PG_FUNCTION_ARGS) values[9] = TransactionIdGetDatum(ControlFile->checkPointCopy.nextMulti); nulls[9] = false; - values[10] = TransactionIdGetDatum(ControlFile->checkPointCopy.nextMultiOffset); + values[10] = Int64GetDatum(ControlFile->checkPointCopy.nextMultiOffset); nulls[10] = false; values[11] = TransactionIdGetDatum(ControlFile->checkPointCopy.oldestXid); diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat index f5867349d14..805a579080d 100644 --- a/src/include/catalog/pg_proc.dat +++ b/src/include/catalog/pg_proc.dat @@ -12346,7 +12346,7 @@ descr => 'pg_controldata checkpoint state information as a function', proname => 'pg_control_checkpoint', provolatile => 'v', prorettype => 'record', proargtypes => '', - proallargtypes => '{pg_lsn,pg_lsn,text,int4,int4,bool,bool,text,oid,xid,xid,xid,oid,xid,xid,oid,xid,xid,int4,timestamptz}', + proallargtypes => '{pg_lsn,pg_lsn,text,int4,int4,bool,bool,text,oid,xid,int8,xid,oid,xid,xid,oid,xid,xid,int4,timestamptz}', proargmodes => '{o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o}', proargnames => '{checkpoint_lsn,redo_lsn,redo_wal_file,timeline_id,prev_timeline_id,full_page_writes,logical_decoding,next_xid,next_oid,next_multixact_id,next_multi_offset,oldest_xid,oldest_xid_dbid,oldest_active_xid,oldest_multi_xid,oldest_multi_dbid,oldest_commit_ts_xid,newest_commit_ts_xid,data_page_checksum_version,checkpoint_time}', prosrc => 'pg_control_checkpoint' }, -- 2.55.0
^ permalink raw reply [nested|flat] 9+ messages in thread

* Re: pg_upgrade silently truncates nextMultiOffset to 32 bits
  2026-08-27 00:59 pg_upgrade silently truncates nextMultiOffset to 32 bits Masahiko Sawada <sawada.mshk@gmail.com>
  2026-08-27 07:06 ` Re: pg_upgrade silently truncates nextMultiOffset to 32 bits Chao Li <li.evan.chao@gmail.com>
  2026-08-27 07:35   ` Re: pg_upgrade silently truncates nextMultiOffset to 32 bits Masahiko Sawada <sawada.mshk@gmail.com>
  2026-08-27 08:20     ` Re: pg_upgrade silently truncates nextMultiOffset to 32 bits Heikki Linnakangas <hlinnaka@iki.fi>
  2026-08-27 08:58       ` Re: pg_upgrade silently truncates nextMultiOffset to 32 bits Heikki Linnakangas <hlinnaka@iki.fi>
  2026-08-27 17:25         ` Re: pg_upgrade silently truncates nextMultiOffset to 32 bits Masahiko Sawada <sawada.mshk@gmail.com>
@ 2026-08-27 17:56           ` Heikki Linnakangas <hlinnaka@iki.fi>
  2026-08-27 21:41             ` Re: pg_upgrade silently truncates nextMultiOffset to 32 bits Masahiko Sawada <sawada.mshk@gmail.com>
  0 siblings, 1 reply; 9+ messages in thread

From: Heikki Linnakangas @ 2026-08-27 17:56 UTC (permalink / raw)
  To: Masahiko Sawada <sawada.mshk@gmail.com>; +Cc: Chao Li <li.evan.chao@gmail.com>; pgsql-hackers

On 27/08/2026 20:25, Masahiko Sawada wrote:
> On Thu, Aug 27, 2026 at 1:58 AM Heikki Linnakangas <hlinnaka@iki.fi> wrote:
>>
>> On 27/08/2026 11:20, Heikki Linnakangas wrote:
>>> On 27/08/2026 10:35, Masahiko Sawada wrote:
>>>> I considered using xid8 instead but it has only comparison operators
>>>> and no arithmetic, so we couldn't compute a delta between two
>>>> checkpoints.
>>>
>>> Hmm, that's a good point, although 'xid' didn't have those operators or
>>> arithmetic either.
>>
>> That was inaccurate: both 'xid' and 'xid8' do have comparison operators.
>> But they don't have a "minus" or "diff" operator, so you indeed cannot
>> easily do "b - a".
>>
>> I don't have a strong opinion, I'm happy with either bigint or xid8
>> here. Bigint is probably more convenient in practice, and it's good to
>> not confuse mxact offsets with transaction ids by abusing the xid8 type.
>> Then again, it was 'xid' before, which had the same issues and we went
>> with 'xid' anyway. Then again, now that it doesn't wrap around anymore,
>> maybe 'bigint' makes more sense now.
> 
> I missed the point that we used to use 'xid' for that field. But I
> agree that 'bigint' makes more sense.
> 
>> Would you like to decide and commit this, or would you prefer me to do it?
> 
> I'm going to take them and go with the 'bigint' column if you're okay.
> 
> I've added the commit messages to the patches.

Ok, thank you!

- Heikki







^ permalink  raw  reply  [nested|flat] 9+ messages in thread

* Re: pg_upgrade silently truncates nextMultiOffset to 32 bits
  2026-08-27 00:59 pg_upgrade silently truncates nextMultiOffset to 32 bits Masahiko Sawada <sawada.mshk@gmail.com>
  2026-08-27 07:06 ` Re: pg_upgrade silently truncates nextMultiOffset to 32 bits Chao Li <li.evan.chao@gmail.com>
  2026-08-27 07:35   ` Re: pg_upgrade silently truncates nextMultiOffset to 32 bits Masahiko Sawada <sawada.mshk@gmail.com>
  2026-08-27 08:20     ` Re: pg_upgrade silently truncates nextMultiOffset to 32 bits Heikki Linnakangas <hlinnaka@iki.fi>
  2026-08-27 08:58       ` Re: pg_upgrade silently truncates nextMultiOffset to 32 bits Heikki Linnakangas <hlinnaka@iki.fi>
  2026-08-27 17:25         ` Re: pg_upgrade silently truncates nextMultiOffset to 32 bits Masahiko Sawada <sawada.mshk@gmail.com>
  2026-08-27 17:56           ` Re: pg_upgrade silently truncates nextMultiOffset to 32 bits Heikki Linnakangas <hlinnaka@iki.fi>
@ 2026-08-27 21:41             ` Masahiko Sawada <sawada.mshk@gmail.com>
  0 siblings, 0 replies; 9+ messages in thread

From: Masahiko Sawada @ 2026-08-27 21:41 UTC (permalink / raw)
  To: Heikki Linnakangas <hlinnaka@iki.fi>; +Cc: Chao Li <li.evan.chao@gmail.com>; pgsql-hackers

On Thu, Aug 27, 2026 at 10:56 AM Heikki Linnakangas <hlinnaka@iki.fi> wrote:
>
> On 27/08/2026 20:25, Masahiko Sawada wrote:
> > On Thu, Aug 27, 2026 at 1:58 AM Heikki Linnakangas <hlinnaka@iki.fi> wrote:
> >>
> >> On 27/08/2026 11:20, Heikki Linnakangas wrote:
> >>> On 27/08/2026 10:35, Masahiko Sawada wrote:
> >>>> I considered using xid8 instead but it has only comparison operators
> >>>> and no arithmetic, so we couldn't compute a delta between two
> >>>> checkpoints.
> >>>
> >>> Hmm, that's a good point, although 'xid' didn't have those operators or
> >>> arithmetic either.
> >>
> >> That was inaccurate: both 'xid' and 'xid8' do have comparison operators.
> >> But they don't have a "minus" or "diff" operator, so you indeed cannot
> >> easily do "b - a".
> >>
> >> I don't have a strong opinion, I'm happy with either bigint or xid8
> >> here. Bigint is probably more convenient in practice, and it's good to
> >> not confuse mxact offsets with transaction ids by abusing the xid8 type.
> >> Then again, it was 'xid' before, which had the same issues and we went
> >> with 'xid' anyway. Then again, now that it doesn't wrap around anymore,
> >> maybe 'bigint' makes more sense now.
> >
> > I missed the point that we used to use 'xid' for that field. But I
> > agree that 'bigint' makes more sense.
> >
> >> Would you like to decide and commit this, or would you prefer me to do it?
> >
> > I'm going to take them and go with the 'bigint' column if you're okay.
> >
> > I've added the commit messages to the patches.
>
> Ok, thank you!

Pushed.

Regards,

-- 
Masahiko Sawada
Amazon Web Services: https://aws.amazon.com






^ permalink  raw  reply  [nested|flat] 9+ messages in thread

* Re: pg_upgrade silently truncates nextMultiOffset to 32 bits
  2026-08-27 00:59 pg_upgrade silently truncates nextMultiOffset to 32 bits Masahiko Sawada <sawada.mshk@gmail.com>
  2026-08-27 07:06 ` Re: pg_upgrade silently truncates nextMultiOffset to 32 bits Chao Li <li.evan.chao@gmail.com>
@ 2026-08-27 08:01   ` Heikki Linnakangas <hlinnaka@iki.fi>
  1 sibling, 0 replies; 9+ messages in thread

From: Heikki Linnakangas @ 2026-08-27 08:01 UTC (permalink / raw)
  To: Chao Li <li.evan.chao@gmail.com>; Masahiko Sawada <sawada.mshk@gmail.com>; +Cc: pgsql-hackers; Heikki Linnakangas <heikki.linnakangas@iki.fi>

On 27/08/2026 10:06, Chao Li wrote:
>> On Aug 27, 2026, at 08:59, Masahiko Sawada <sawada.mshk@gmail.com> wrote:
>>
>> Hi all,
>> (CCing Heikki as the committer of commit bd8d9c9bdfa)
>>
>> Commit bd8d9c9bdfa widened MultiXactOffset to uint64, but I found that
>> pg_upgrade still reads it as a uint32 value when reading the
>> pg_controldata continents:
>>
>> else if ((p = strstr(bufin, "Latest checkpoint's NextMultiOffset:")) != NULL)
>> {
>> :
>>     p++;                /* remove ':' char */
>>     cluster->controldata.chkpnt_nxtmxoff = str2uint(p);
>>
>> I think it should use strtou64() instead. The attached 0001 patch
>> fixes it. It introduces str2uint64() as other fields are read by a
>> similar helper function str2uint().
>>
>> Also, when checking other similar codes around the new
>> MultiXactOffset, I found that pg_control_checkpoint() still reports
>> the value as an xid. I think we should report it as bigint instead.
>> What do you think? The attached 0002 patch fixes it.

Thanks, good catch!

> bigint is a signed int64, so it cannot represent the full uint64 range, although perhaps this is only a theoretical concern. If we want to avoid this limitation, should we use numeric instead?

xid8 seems like the most straightforward replacement. It's a little 
bogus as a multixact offset it's not really an XID. But we were using 
the 32-bit 'xid' type for it previously, it's in line with that.

I'll go do that. This requires bumping the catalog version, but since 
we've bumped it already since 19beta3, that's OK.

- Heikki





^ permalink  raw  reply  [nested|flat] 9+ messages in thread


end of thread, other threads:[~2026-08-27 21:41 UTC | newest]

Thread overview: 9+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2026-08-27 00:59 pg_upgrade silently truncates nextMultiOffset to 32 bits Masahiko Sawada <sawada.mshk@gmail.com>
2026-08-27 07:06 ` Chao Li <li.evan.chao@gmail.com>
2026-08-27 07:35   ` Masahiko Sawada <sawada.mshk@gmail.com>
2026-08-27 08:20     ` Heikki Linnakangas <hlinnaka@iki.fi>
2026-08-27 08:58       ` Heikki Linnakangas <hlinnaka@iki.fi>
2026-08-27 17:25         ` Masahiko Sawada <sawada.mshk@gmail.com>
2026-08-27 17:56           ` Heikki Linnakangas <hlinnaka@iki.fi>
2026-08-27 21:41             ` Masahiko Sawada <sawada.mshk@gmail.com>
2026-08-27 08:01   ` Heikki Linnakangas <hlinnaka@iki.fi>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox