pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Fujii Masao <fujii@postgresql.org>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: xid_wraparound: Fix XID consumption accounting
Date: Wed, 18 Nov 2026 05:00:06 +0000
Message-ID: <E1xTXm9-00000000BvQ-0tuD@gemulon.postgresql.org> (raw)

xid_wraparound: Fix XID consumption accounting

When the current transaction had not yet been assigned a top-level
XID, consume_xids(n) consumed n + 1 XIDs because the initial top-level
XID allocation was not included in the count. Include that allocation
so that the function consumes exactly n XIDs.

In particular, consume_xids(1) now consumes and returns only the
top-level XID in this case, rather than consuming two XIDs and
returning the second. consume_xids(0) now raises an error instead of
returning the next unallocated XID.

With 32kB blocks, bulk XID consumption could also consume more XIDs
than requested or return an outdated XID. Restrict this optimization
so that consume_xids(n) always consumes exactly n XIDs and returns
the last XID it assigned.

Backpatch to 17, where the xid_wraparound test module was introduced.

Author: Yushi Ogiwara <btogiwarayuushi@oss.nttdata.com>
Author: João Rito <joaovictor.rito@gmail.com>
Reviewed-by: Masahiko Sawada <sawada.mshk@gmail.com>
Reviewed-by: Fujii Masao <masao.fujii@gmail.com>
Discussion: https://postgr.es/m/2a62f138c9dcb6fcf5889b076d123aa2@oss.nttdata.com
Backpatch-through: 17

Branch
------
REL_18_STABLE

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

Modified Files
--------------
src/test/modules/xid_wraparound/xid_wraparound.c | 52 ++++++++++++++++--------
1 file changed, 36 insertions(+), 16 deletions(-)



view thread (4+ messages)  latest in thread

Message-ID: <E1xTXm9-00000000BvQ-0tuD@gemulon.postgresql.org>
Permalink:  ../E1xTXm9-00000000BvQ-0tuD@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1xTXm9-00000000BvQ-0tuD@gemulon.postgresql.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-committers@postgresql.org
  Cc: fujii@postgresql.org
  Subject: Re: pgsql: xid_wraparound: Fix XID consumption accounting
  In-Reply-To: <E1xTXm9-00000000BvQ-0tuD@gemulon.postgresql.org>
  References: <E1xTXm9-00000000BvQ-0tuD@gemulon.postgresql.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

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