postgresql/src/backend
Fujii Masao 8e684ce11d Fix unlogged sequence corruption after standby promotion
Previously, if an unlogged sequence was created on the primary and
replicated to a standby, reading the sequence after promoting the
standby (for example, with nextval()) could trigger the following
assertion failure:

    TRAP: failed Assert("((const PageHeaderData *) page)->pd_special >= SizeOfPageHeaderData")

In non-assert builds, the same operation could instead fail with an
error such as:

    ERROR:  bad magic number in sequence

The problem was that seq_redo() updated the init fork page in shared
buffers but did not flush it to disk. During promotion,
ResetUnloggedRelations() recreates the main fork of unlogged
relations by copying the init fork from disk, bypassing shared
buffers. As a result, the main fork could be recreated from a stale
init fork instead of the WAL-replayed page.

Fix this by introducing a helper to flush init fork buffers
immediately, and make seq_redo() use it. As a result, the main fork
of an unlogged sequence is recreated from the up-to-date init fork on
disk, allowing the unlogged sequence to be read successfully after
standby promotion.

Backpatch to v15, where unlogged sequences were introduced.

Author: Fujii Masao <masao.fujii@gmail.com>
Reviewed-by: vignesh C <vignesh21@gmail.com>
Discussion: https://postgr.es/m/CAHGQGwH1Ssze3XM6wjoTjSLVOR041c6xP+vsdLP951=w8oG8bA@mail.gmail.com
Backpatch-through: 15
2026-06-30 08:48:47 +09:00
..
access Fix unlogged sequence corruption after standby promotion 2026-06-30 08:48:47 +09:00
archive Don't include wait_event.h in pgstat.h 2026-03-06 16:24:58 +01:00
backup Pre-beta mechanical code beautification, step 1: run pgindent. 2026-05-13 10:34:17 -04:00
bootstrap Rework signal handler infrastructure to pass sender info as argument. 2026-04-15 07:30:34 -04:00
catalog Readable identity strings for property graph objects 2026-06-23 09:13:11 +02:00
commands Fix unlogged sequence corruption after standby promotion 2026-06-30 08:48:47 +09:00
executor Reject child partition FDWs in FOR PORTION OF 2026-06-27 19:36:51 +02:00
foreign Remove bits* typedefs. 2026-03-30 16:12:08 -05:00
jit Update JIT tuple deforming code for virtual generated columns 2026-06-19 15:26:18 +12:00
lib Pre-beta mechanical code beautification, step 1: run pgindent. 2026-05-13 10:34:17 -04:00
libpq Fix md5_password_warnings for role and database settings 2026-06-12 08:32:39 +09:00
main Update copyright for 2026 2026-01-01 13:24:10 -05:00
nodes IS JSON/JSON(): Protect against expressions uncoercible to text 2026-06-11 16:17:58 +02:00
optimizer Move FOR PORTION OF volatile check into planner 2026-06-27 13:51:11 +02:00
parser Forbid FOR PORTION OF with WHERE CURRENT OF 2026-06-29 15:17:10 +02:00
partitioning Reject degenerate SPLIT PARTITION with DEFAULT partition 2026-05-25 11:57:42 +03:00
po Translation updates 2026-06-01 12:13:54 +02:00
port Use "grep -E" not "egrep". 2026-05-13 12:07:19 -04:00
postmaster Distinguish datacheckums worker invocations more reliably 2026-06-24 15:07:33 +03:00
regex Harden our regex engine against integer overflow in size calculations. 2026-05-11 05:13:46 -07:00
replication Fix misreporting of publisher sequence permissions during sync 2026-06-20 18:19:23 +09:00
rewrite Fix LATERAL references in GRAPH_TABLE with multi-label pattern 2026-06-05 09:27:51 +02:00
snowball Fix meson build of snowball code. 2026-01-05 16:51:36 -05:00
statistics Simplify some stats restore code with InputFunctionCallSafe() 2026-06-30 08:30:08 +09:00
storage Make StandbyAcquireAccessExclusiveLock() more resilent with OOMs 2026-06-20 15:00:40 +09:00
tcop Simplify signature of ProcessStartupPacket() 2026-05-17 07:44:17 +09:00
tsearch dict_synonym.c: remove incorrect outlen. 2026-06-08 11:47:53 -07:00
utils Hardwire RI fast-path end-of-xact cleanup into xact.c 2026-06-29 10:24:28 +09:00
.gitignore
common.mk Blind attempt to fix LLVM dependency in the backend 2022-09-15 10:53:48 +07:00
Makefile ssl: Serverside SNI support for libpq 2026-03-18 12:37:11 +01:00
meson.build Add CONCURRENTLY option to REPACK 2026-04-06 21:55:08 +02:00
nls.mk Create a separate file listing backend types 2025-09-26 15:21:49 +02:00