postgresql/src/include
Tomas Vondra 5b3f63a1bf Use GetXLogInsertEndRecPtr in gistGetFakeLSN
The function used GetXLogInsertRecPtr() to generate the fake LSN. Most
of the time this is the same as what XLogInsert() would return, and so
it works fine with the XLogFlush() call. But if the last record ends at
a page boundary, GetXLogInsertRecPtr() returns LSN pointing after the
page header. In such case XLogFlush() fails with errors like this:

  ERROR: xlog flush request 0/01BD2018 is not satisfied --- flushed only to 0/01BD2000

Such failures are very hard to trigger, particularly outside aggressive
test scenarios.

Fixed by introducing GetXLogInsertEndRecPtr(), returning the correct LSN
without skipping the header. This is the same as GetXLogInsertRecPtr(),
except that it calls XLogBytePosToEndRecPtr().

Initial investigation by me, root cause identified by Andres Freund.

This is a long-standing bug in gistGetFakeLSN(), probably introduced by
c6b92041d3 in PG13. Backpatch to all supported versions.

Reported-by: Peter Geoghegan <pg@bowt.ie>
Reviewed-by: Andres Freund <andres@anarazel.de>
Reviewed-by: Noah Misch <noah@leadboat.com>
Discussion: https://postgr.es/m/vf4hbwrotvhbgcnknrqmfbqlu75oyjkmausvy66ic7x7vuhafx@e4rvwavtjswo
Backpatch-through: 14
2026-03-13 23:26:02 +01:00
..
access Use GetXLogInsertEndRecPtr in gistGetFakeLSN 2026-03-13 23:26:02 +01:00
archive
backup
bootstrap
catalog Avoid name collision with NOT NULL constraints 2026-02-21 12:22:08 +01:00
commands Harden _int_matchsel() against being attached to the wrong operator. 2026-02-09 10:14:22 -05:00
common
datatype
executor Fix EvalPlanQual handling of foreign/custom joins in ExecScanFetch. 2025-10-15 17:15:01 +09:00
fe_utils
foreign
jit
lib Fix reset of incorrect hash iterator in GROUPING SETS queries 2025-10-18 16:07:41 +13:00
libpq
mb Replace pg_mblen() with bounds-checked versions. 2026-02-09 12:43:42 +13:00
nodes Fix query jumbling with GROUP BY clauses 2026-01-14 08:44:52 +09:00
optimizer Strip PlaceHolderVars from index operands 2025-12-29 11:43:06 +09:00
parser
partitioning
pch
port Fix O_CLOEXEC flag handling in Windows port. 2025-12-10 09:05:21 +13:00
portability
postmaster Fix incorrect const qualifier 2025-09-16 07:23:50 +02:00
regex
replication Make invalid primary_slot_name follow standard GUC error reporting. 2025-10-22 20:10:58 +09:00
rewrite
snowball
statistics Fix redefinition of typedef RangeVar. 2025-10-15 13:14:00 -05:00
storage Fix OldestMemberMXactId and OldestVisibleMXactId array usage 2026-03-02 19:19:26 +02:00
tcop
tsearch Replace pg_mblen() with bounds-checked versions. 2026-02-09 12:43:42 +13:00
utils Guard against unexpected dimensions of oidvector/int2vector. 2026-02-09 09:57:44 -05:00
.gitignore
c.h Allow PG_PRINTF_ATTRIBUTE to be different in C and C++ code. 2026-02-25 11:57:26 -05:00
fmgr.h
funcapi.h
getopt_long.h
Makefile Fix build inconsistency due to the generation of wait-event code 2026-02-02 08:02:59 +09:00
meson.build
miscadmin.h Avoid mixing void and integer in a conditional expression. 2025-11-02 12:31:01 -05:00
pg_config.h.in Allow PG_PRINTF_ATTRIBUTE to be different in C and C++ code. 2026-02-25 11:57:26 -05:00
pg_config_manual.h
pg_getopt.h
pg_trace.h
pgstat.h Don't include execnodes.h in replication/conflict.h 2025-09-25 14:52:19 +02:00
pgtar.h
pgtime.h
port.h Fix O_CLOEXEC flag handling in Windows port. 2025-12-10 09:05:21 +13:00
postgres.h
postgres_ext.h Move pg_int64 back to postgres_ext.h 2025-09-16 10:48:44 +02:00
postgres_fe.h
varatt.h
windowapi.h