pgsql: Widen Object ID counter to 8 bytes

From: Michael Paquier <michael(at)paquier(dot)xyz>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Widen Object ID counter to 8 bytes
Date: 2026-09-10 00:43:36
Message-ID: E1x4St5-00000004Cdl-1zsh@gemulon.postgresql.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Widen Object ID counter to 8 bytes

This commit adds a new routine called GetNewObjectId8() in varsup.c,
which is able to retrieve a 8-byte OID, based on the next OID retrieved
from the control file. GetNewObjectId() is kept compatible with its
origin, where we still check that the lower 32 bits of the counter do
not wraparound, while handling the FirstNormalObjectId case.

This change is combined with an update of the control file, with
CheckPoint.nextOid enlarged from Oid to Oid8. pg_control_checkpoint(),
pg_resetwal and pg_upgrade are updated to adapt to this change, to make
sure that the value is not truncated due to 32-bit limitations when
used, making an upgrade to a newer version where 8-byte is supported a
transparent operation.

A couple of comments in the xlog redo logic referred to wraparound
issues, which is not the case anymore with this change in place, so
refresh these.

This change is required to be able to support external TOAST pointers
based on Oid8, under discussion, and can be used for other purposes.

Tests are added for pg_upgrade (2^32 value carried across upgrades),
pg_resetwal and pg_control_checkpoint(), hence across all the tools
that need to be covered by this change.

Bump catalog version.
Bump PG_CONTROL_VERSION.
Bump XLOG_PAGE_MAGIC, due to XLOG_NEXTOID.

Author: Michael Paquier <michael(at)paquier(dot)xyz>
Reviewed-by: Greg Burd <greg(at)burd(dot)me>
Reviewed-by: Bharath Rupireddy <bharath(dot)rupireddyforpostgres(at)gmail(dot)com>
Reviewed-by: Yugo Nagata <nagata(at)sraoss(dot)co(dot)jp>
Discussion: https://postgr.es/m/af19kUjwjhaoUTLn@paquier.xyz

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/cb298616463d6e4f2c360e8d07b83b526fad375f

Modified Files
--------------
doc/src/sgml/func/func-info.sgml | 2 +-
doc/src/sgml/ref/pg_resetwal.sgml | 10 +++---
src/backend/access/rmgrdesc/xlogdesc.c | 8 ++---
src/backend/access/transam/varsup.c | 59 +++++++++++++++++++++----------
src/backend/access/transam/xlog.c | 26 +++++++-------
src/backend/access/transam/xlogrecovery.c | 2 +-
src/backend/utils/misc/pg_controldata.c | 2 +-
src/bin/pg_controldata/pg_controldata.c | 2 +-
src/bin/pg_resetwal/pg_resetwal.c | 10 +++---
src/bin/pg_resetwal/t/001_basic.pl | 17 +++++++++
src/bin/pg_upgrade/controldata.c | 2 +-
src/bin/pg_upgrade/pg_upgrade.c | 2 +-
src/bin/pg_upgrade/pg_upgrade.h | 2 +-
src/bin/pg_upgrade/t/002_pg_upgrade.pl | 25 +++++++++++++
src/include/access/transam.h | 8 +++--
src/include/access/xlog.h | 2 +-
src/include/access/xlog_internal.h | 2 +-
src/include/catalog/catversion.h | 2 +-
src/include/catalog/pg_control.h | 4 +--
src/include/catalog/pg_proc.dat | 2 +-
20 files changed, 129 insertions(+), 60 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Fujii Masao 2026-09-10 00:48:10 pgsql: postgres_fdw: Fix crash when estimating joins with functions
Previous Message Robert Haas 2026-09-09 22:39:46 pgsql: pg_plan_advice: Add CHECK_FOR_INTERRUPTS() and check_stack_depth