| From: | Melanie Plageman <melanieplageman(at)gmail(dot)com> |
|---|---|
| To: | pgsql-committers(at)lists(dot)postgresql(dot)org |
| Subject: | pgsql: Fix WAL-logged CREATE DATABASE with nonstandard pages |
| Date: | 2026-11-19 21:13:14 |
| Message-ID: | E1xU9RR-00000000QqF-1T5Q@gemulon.postgresql.org |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-committers |
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(at)gmail(dot)com>
Reported-by: Rogers Wang <rogers(dot)ww(at)qq(dot)com>
Reviewed-by: surya poondla <suryapoondla4(at)gmail(dot)com>
Reviewed-by: Robert Haas <robertmhaas(at)gmail(dot)com>
Reviewed-by: Zhijie Hou <houzhijie22(at)gmail(dot)com>
Author: Melanie Plageman <melanieplageman(at)gmail(dot)com>
Discussion: https://postgr.es/m/flat/CAEze2WgNjODiAiTU18E06_BrRK0nqwJ1kdS_bN61c2_DpFDSnQ%40mail.gmail.com
Backpatch-through: 15
Branch
------
REL_17_STABLE
Details
-------
https://git.postgresql.org/pg/commitdiff/a131a43ef76b7efd4f20736ae3eaef5e8ddaa2eb
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/include/utils/memutils.h | 14 +++++++++
src/test/recovery/Makefile | 1 +
src/test/recovery/t/034_create_database.pl | 43 +++++++++++++++++++++++++-
8 files changed, 140 insertions(+), 16 deletions(-)
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Melanie Plageman | 2026-11-19 21:15:34 | pgsql: Fix WAL-logged CREATE DATABASE with nonstandard pages |
| Previous Message | Peter Geoghegan | 2026-11-19 21:10:31 | pgsql: Fix SP-GiST index-only scans with non-returnable keys. |