pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
pgsql: Fix WAL-logged CREATE DATABASE with nonstandard pages
6+ messages / 1 participants
[nested] [flat]

* pgsql: Fix WAL-logged CREATE DATABASE with nonstandard pages
@ 2026-11-19 21:03  Melanie Plageman <melanieplageman@gmail.com>
  0 siblings, 0 replies; 6+ messages in thread

From: Melanie Plageman @ 2026-11-19 21:03 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

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
------
master

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

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



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

* pgsql: Fix WAL-logged CREATE DATABASE with nonstandard pages
@ 2026-11-19 21:06  Melanie Plageman <melanieplageman@gmail.com>
  0 siblings, 0 replies; 6+ messages in thread

From: Melanie Plageman @ 2026-11-19 21:06 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

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_19_STABLE

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

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(-)



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

* pgsql: Fix WAL-logged CREATE DATABASE with nonstandard pages
@ 2026-11-19 21:09  Melanie Plageman <melanieplageman@gmail.com>
  0 siblings, 0 replies; 6+ messages in thread

From: Melanie Plageman @ 2026-11-19 21:09 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

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(-)



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

* pgsql: Fix WAL-logged CREATE DATABASE with nonstandard pages
@ 2026-11-19 21:13  Melanie Plageman <melanieplageman@gmail.com>
  0 siblings, 0 replies; 6+ messages in thread

From: Melanie Plageman @ 2026-11-19 21:13 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

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_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(-)



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

* pgsql: Fix WAL-logged CREATE DATABASE with nonstandard pages
@ 2026-11-19 21:15  Melanie Plageman <melanieplageman@gmail.com>
  0 siblings, 0 replies; 6+ messages in thread

From: Melanie Plageman @ 2026-11-19 21:15 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

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_16_STABLE

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

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                 |  5 +++-
src/test/recovery/t/034_create_database.pl | 43 +++++++++++++++++++++++++-
8 files changed, 143 insertions(+), 17 deletions(-)



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

* pgsql: Fix WAL-logged CREATE DATABASE with nonstandard pages
@ 2026-11-19 21:21  Melanie Plageman <melanieplageman@gmail.com>
  0 siblings, 0 replies; 6+ messages in thread

From: Melanie Plageman @ 2026-11-19 21:21 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

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_15_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/0b1f7b527366d8c540796bf8d2f2457bef43638b

Modified Files
--------------
src/backend/access/transam/xloginsert.c    | 13 ++++-----
src/backend/commands/dbcommands.c          | 19 ++++++++++++-
src/backend/storage/buffer/bufmgr.c        | 45 ++++++++++++++++++++++++++----
src/include/storage/bufmgr.h               |  4 +++
src/include/storage/bufpage.h              | 14 ++++++++++
src/include/utils/memutils.h               | 14 ++++++++++
src/test/recovery/Makefile                 |  2 +-
src/test/recovery/t/034_create_database.pl | 43 +++++++++++++++++++++++++++-
8 files changed, 137 insertions(+), 17 deletions(-)



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


end of thread, other threads:[~2026-11-19 21:21 UTC | newest]

Thread overview: 6+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2026-11-19 21:03 pgsql: Fix WAL-logged CREATE DATABASE with nonstandard pages Melanie Plageman <melanieplageman@gmail.com>
2026-11-19 21:06 pgsql: Fix WAL-logged CREATE DATABASE with nonstandard pages Melanie Plageman <melanieplageman@gmail.com>
2026-11-19 21:09 pgsql: Fix WAL-logged CREATE DATABASE with nonstandard pages Melanie Plageman <melanieplageman@gmail.com>
2026-11-19 21:13 pgsql: Fix WAL-logged CREATE DATABASE with nonstandard pages Melanie Plageman <melanieplageman@gmail.com>
2026-11-19 21:15 pgsql: Fix WAL-logged CREATE DATABASE with nonstandard pages Melanie Plageman <melanieplageman@gmail.com>
2026-11-19 21:21 pgsql: Fix WAL-logged CREATE DATABASE with nonstandard pages Melanie Plageman <melanieplageman@gmail.com>

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