postgresql/src
Michael Paquier 16b89ff048 Fix race with timeline selection in logical decoding during promotion
During promotion, there is a window where RecoveryInProgress() returns
true but the WAL segments of the old timeline have already been removed.
A logical decoding could pick up the old timeline in this window when
reading a page, failing with the following error:
ERROR: requested WAL segment ... has already been removed

This issue does not lead to any data correctness issue, as retrying to
decode the data works in follow-up decoding attempts.  It impacts
availability, though.  Other WAL page read callbacks have a similar
issue, this commit takes care of what should be the noisiest code path:
logical decoding with START_REPLICATION in a WAL sender.

A TAP test, based on an injection point waiting in the startup process
after the segments have been removed/recycled, is added.  This part is
backpatched down to v17.

This issue has been causing sporadic failures in the buildfarm, and
was reproducible manually.  This issue happens since logical decoding on
standbys exists, down to v16.

Reported-by: Alexander Lakhin <exclusion@gmail.com>
Author: Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
Reviewed-by: Hayato Kuroda <kuroda.hayato@fujitsu.com>
Reviewed-by: Xuneng Zhou <xunengzhou@gmail.com>
Discussion: https://postgr.es/m/7daef094-abf3-4672-bc23-3df4763b16a3@gmail.com
Backpatch-through: 16
2026-06-11 17:29:39 +09:00
..
backend Fix race with timeline selection in logical decoding during promotion 2026-06-11 17:29:39 +09:00
bin pg_createsubscriber: Fix cleanup of publisher-side objects after errors 2026-05-27 10:35:49 +09:00
common Fix off-by-one with NFC recomposition for Hangul U+11A7 (TBASE) 2026-06-05 07:50:13 +09:00
fe_utils psql: Fix expanded aligned output 2026-06-08 14:37:57 +09:00
include Fix missed checks for hashability of container-type equality. 2026-06-08 11:48:17 -04:00
interfaces ecpg: Reject multiple header items in GET/SET DESCRIPTOR 2026-06-08 17:11:12 +09:00
makefiles Optimize pg_popcount() with AVX-512 instructions. 2024-04-06 21:56:23 -05:00
pl Make plpgsql_trap test more robust and less resource-intensive. 2026-04-21 10:54:39 -04:00
port Prevent path traversal in pg_basebackup and pg_rewind 2026-05-11 05:13:49 -07:00
template Remove AIX support 2024-02-28 15:17:23 +04:00
test Fix race with timeline selection in logical decoding during promotion 2026-06-11 17:29:39 +09:00
timezone Guard against unsafe conditions in usage of pg_strftime(). 2026-05-11 05:13:49 -07:00
tools Consider collation when proving subquery uniqueness 2026-05-05 10:29:01 +09:00
tutorial Update copyright for 2024 2024-01-03 20:49:05 -05:00
.gitignore
DEVELOPERS
Makefile Remove distprep 2023-11-06 15:18:04 +01:00
Makefile.global.in Don't put library-supplied -L/-I switches before user-supplied ones. 2025-07-29 15:17:41 -04:00
Makefile.shlib Remove AIX support 2024-02-28 15:17:23 +04:00
meson.build Update copyright for 2024 2024-01-03 20:49:05 -05:00
nls-global.mk Fix update-po for the PGXS case 2025-10-16 20:21:05 +02:00