pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Melanie Plageman <melanieplageman@gmail.com>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Fix WAL-logged CREATE DATABASE with nonstandard pages
Date: Thu, 19 Nov 2026 21:09:15 +0000
Message-ID: <E1xU9Na-00000000Qki-40Cc@gemulon.postgresql.org> (raw)

Fix WAL-logged CREATE DATABASE with nonstandard pages

RelationCopyStorageUsingBuffer() passed page_std=true when WAL-logging
every copied relation fork. This allowed WAL insertion to omit the
region between pd_lower and pd_upper from full-page images and restore
it as zeroes during replay.

That is safe only for pages using the standard page layout. On
nonstandard pages, the apparent hole can contain meaningful data,
causing the primary and standby to diverge. Known affected cases include
free space maps, visibility maps, and old GIN indexes, though any access
method using nonstandard pages could be affected.

Losing VM contents can lead to data corruption after promotion. For
example, a tuple lock on a promoted standby may find the all-frozen bit
already clear and therefore emit no WAL to clear it. The old primary
then replays the xmax change without clearing the all-frozen bit,
retaining the stale bit. This can cause vacuum failures and make
invisible data visible again.

Only remove the apparent free-space region from WAL when copying a heap
table or B-tree index, whose pages are known to use the standard layout.
For other relation types, remove the region only when it contains all
zeroes, ensuring that replay reconstructs the page without data loss.
Use a shared bounds helper so that RelationCopyStorageUsingBuffer()
checks the same region that XLogRecordAssemble() omits.

This may increase WAL volume for access methods other than heap and
B-tree when the space between pd_lower and pd_upper contains stale data
that was previously omitted. Such access methods can preserve hole
removal by zeroing that space.

Reported-by: Matthias van de Meent <boekewurm+postgres@gmail.com>
Reported-by: Rogers Wang <rogers.ww@qq.com>
Reviewed-by: surya poondla <suryapoondla4@gmail.com>
Reviewed-by: Robert Haas <robertmhaas@gmail.com>
Reviewed-by: Zhijie Hou <houzhijie22@gmail.com>
Author: Melanie Plageman <melanieplageman@gmail.com>
Discussion: https://postgr.es/m/flat/CAEze2WgNjODiAiTU18E06_BrRK0nqwJ1kdS_bN61c2_DpFDSnQ%40mail.gmail.com
Backpatch-through: 15

Branch
------
REL_18_STABLE

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

Modified Files
--------------
src/backend/access/transam/xloginsert.c    | 13 ++++----
src/backend/commands/dbcommands.c          | 19 +++++++++++-
src/backend/storage/buffer/bufmgr.c        | 48 ++++++++++++++++++++++++++----
src/include/storage/bufmgr.h               |  4 +++
src/include/storage/bufpage.h              | 14 +++++++++
src/test/recovery/Makefile                 |  1 +
src/test/recovery/t/034_create_database.pl | 43 +++++++++++++++++++++++++-
7 files changed, 126 insertions(+), 16 deletions(-)



view thread (6+ messages)  latest in thread

Message-ID: <E1xU9Na-00000000Qki-40Cc@gemulon.postgresql.org>
Permalink:  ../E1xU9Na-00000000Qki-40Cc@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1xU9Na-00000000Qki-40Cc@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: melanieplageman@gmail.com
  Subject: Re: pgsql: Fix WAL-logged CREATE DATABASE with nonstandard pages
  In-Reply-To: <E1xU9Na-00000000Qki-40Cc@gemulon.postgresql.org>
  References: <E1xU9Na-00000000Qki-40Cc@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