postgresql/src/include/access
Michael Paquier 17b2d5ec75 Fix unconditional WAL receiver shutdown during stream-archive transition
Commit b4f584f9d2 (affecting v15~, later backpatched down to 13 as of
3635a0a35a) introduced an unconditional WAL receiver shutdown when
switching from streaming to archive WAL sources.  This causes problems
during a timeline switch, when a WAL receiver enters WALRCV_WAITING
state but remains alive, waiting for instructions.

The unconditional shutdown can break some monitoring scenarios as the
WAL receiver gets repeatedly terminated and re-spawned, causing
pg_stat_wal_receiver.status to show a "streaming" instead of "waiting"
status, masking the fact that the WAL receiver is waiting for a new TLI
and a new LSN to be able to continue streaming.

This commit changes the WAL receiver behavior so as the shutdown becomes
conditional, with InstallXLogFileSegmentActive being always reset to
prevent the regression fixed by b4f584f9d2: only terminate the WAL
receiver when it is actively streaming (WALRCV_STREAMING,
WALRCV_STARTING, or WALRCV_RESTARTING).  When in WALRCV_WAITING state,
just reset InstallXLogFileSegmentActive flag to allow archive
restoration without killing the process.  WALRCV_STOPPED and
WALRCV_STOPPING are not reachable states in this code path.  For the
latter, the startup process is the one in charge of setting
WALRCV_STOPPING via ShutdownWalRcv(), waiting for the WAL receiver to
reach a WALRCV_STOPPED state after switching walRcvState, so
WaitForWALToBecomeAvailable() cannot be reached while a WAL receiver is
in a WALRCV_STOPPING state.

A regression test is added to check that a WAL receiver is not stopped
on timeline jump, that fails when the fix of this commit is reverted.

Reported-by: Ryan Bird <ryanzxg@gmail.com>
Author: Xuneng Zhou <xunengzhou@gmail.com>
Reviewed-by: Noah Misch <noah@leadboat.com>
Reviewed-by: Michael Paquier <michael@paquier.xyz>
Discussion: https://postgr.es/m/19093-c4fff49a608f82a0@postgresql.org
Backpatch-through: 13
2025-11-04 10:47:38 +09:00
..
amapi.h Do a tiny bit of header file maintenance 2025-09-30 12:28:29 +02:00
amvalidate.h Update copyright for 2025 2025-01-01 11:21:55 -05:00
attmap.h Update copyright for 2025 2025-01-01 11:21:55 -05:00
attnum.h Update copyright for 2025 2025-01-01 11:21:55 -05:00
brin.h Don't include execnodes.h in brin.h or gin.h 2025-10-05 17:35:25 +02:00
brin_internal.h Update some more forward declarations to use typedef 2025-09-25 14:33:19 +02:00
brin_page.h Update copyright for 2025 2025-01-01 11:21:55 -05:00
brin_pageops.h Add some const qualifications 2025-10-27 09:55:59 +01:00
brin_revmap.h Update copyright for 2025 2025-01-01 11:21:55 -05:00
brin_tuple.h Update copyright for 2025 2025-01-01 11:21:55 -05:00
brin_xlog.h Update copyright for 2025 2025-01-01 11:21:55 -05:00
bufmask.h Update copyright for 2025 2025-01-01 11:21:55 -05:00
clog.h Update copyright for 2025 2025-01-01 11:21:55 -05:00
cmptype.h Convert strategies to and from compare types 2025-02-02 10:26:04 +01:00
commit_ts.h Remove leftover dead code from commit_ts.h. 2025-07-03 23:39:45 +09:00
detoast.h Update copyright for 2025 2025-01-01 11:21:55 -05:00
genam.h Do a tiny bit of header file maintenance 2025-09-30 12:28:29 +02:00
generic_xlog.h Update copyright for 2025 2025-01-01 11:21:55 -05:00
gin.h Don't include execnodes.h in brin.h or gin.h 2025-10-05 17:35:25 +02:00
gin_private.h Fix some confusing uses of const 2025-10-30 11:20:04 +01:00
gin_tuple.h Fix various incorrect filename references 2025-09-22 13:33:17 +12:00
ginblock.h Update copyright for 2025 2025-01-01 11:21:55 -05:00
ginxlog.h Add comment in ginxlog.h about block used with ginxlogInsertListPage 2025-10-06 16:23:51 +09:00
gist.h Rename gist stratnum support function 2025-06-02 08:41:27 +02:00
gist_private.h Update copyright for 2025 2025-01-01 11:21:55 -05:00
gistscan.h Update copyright for 2025 2025-01-01 11:21:55 -05:00
gistxlog.h Update copyright for 2025 2025-01-01 11:21:55 -05:00
hash.h Mark function arguments of type "Datum *" as "const Datum *" where possible 2025-10-31 10:47:25 +01:00
hash_xlog.h Fix description of WAL record blocks in hash_xlog.h 2025-09-11 17:17:04 +09:00
heapam.h Mark ItemPointer arguments as const throughout 2025-10-30 14:12:06 +01:00
heapam_xlog.h Eliminate XLOG_HEAP2_VISIBLE from vacuum phase III 2025-10-13 18:01:06 -04:00
heaptoast.h Mark function arguments of type "Datum *" as "const Datum *" where possible 2025-10-31 10:47:25 +01:00
hio.h Update copyright for 2025 2025-01-01 11:21:55 -05:00
htup.h Remove PointerIsValid() 2025-09-24 15:17:20 +02:00
htup_details.h Fix type of infomask parameter in htup_details.h functions. 2025-10-22 16:47:38 -05:00
itup.h Remove PointerIsValid() 2025-09-24 15:17:20 +02:00
multixact.h Refactor ReadMultiXactCounts() into GetMultiXactInfo() 2025-08-19 14:04:09 +09:00
nbtree.h Mark ItemPointer arguments as const throughout 2025-10-30 14:12:06 +01:00
nbtxlog.h Update copyright for 2025 2025-01-01 11:21:55 -05:00
parallel.h Rename some signal and interrupt handling functions for consistency 2025-03-05 16:22:26 +02:00
printsimple.h Update copyright for 2025 2025-01-01 11:21:55 -05:00
printtup.h Update copyright for 2025 2025-01-01 11:21:55 -05:00
relation.h Update copyright for 2025 2025-01-01 11:21:55 -05:00
reloptions.h Rename transformRelOptions()'s "namspace" parameter to "nameSpace". 2025-08-06 12:08:07 -05:00
relscan.h Show index search count in EXPLAIN ANALYZE, take 2. 2025-03-11 09:20:50 -04:00
rewriteheap.h Update copyright for 2025 2025-01-01 11:21:55 -05:00
rmgr.h Pre-beta mechanical code beautification. 2022-05-12 15:17:30 -04:00
rmgrdesc_utils.h Update copyright for 2025 2025-01-01 11:21:55 -05:00
rmgrlist.h Update copyright for 2025 2025-01-01 11:21:55 -05:00
sdir.h Update copyright for 2025 2025-01-01 11:21:55 -05:00
sequence.h Update copyright for 2025 2025-01-01 11:21:55 -05:00
session.h Update copyright for 2025 2025-01-01 11:21:55 -05:00
skey.h Update copyright for 2025 2025-01-01 11:21:55 -05:00
slru.h Update outdated references to the SLRU ControlLock 2025-09-03 10:20:28 +09:00
spgist.h Update copyright for 2025 2025-01-01 11:21:55 -05:00
spgist_private.h Mark function arguments of type "Datum *" as "const Datum *" where possible 2025-10-31 10:47:25 +01:00
spgxlog.h Update copyright for 2025 2025-01-01 11:21:55 -05:00
stratnum.h Update copyright for 2025 2025-01-01 11:21:55 -05:00
subtrans.h Update copyright for 2025 2025-01-01 11:21:55 -05:00
syncscan.h Update copyright for 2025 2025-01-01 11:21:55 -05:00
sysattr.h Update copyright for 2025 2025-01-01 11:21:55 -05:00
table.h Update copyright for 2025 2025-01-01 11:21:55 -05:00
tableam.h Update some more forward declarations to use typedef 2025-09-25 14:33:19 +02:00
tidstore.h Mark ItemPointer arguments as const throughout 2025-10-30 14:12:06 +01:00
timeline.h Update copyright for 2025 2025-01-01 11:21:55 -05:00
toast_compression.h Update copyright for 2025 2025-01-01 11:21:55 -05:00
toast_helper.h Update copyright for 2025 2025-01-01 11:21:55 -05:00
toast_internals.h Update copyright for 2025 2025-01-01 11:21:55 -05:00
transam.h Inline TransactionIdFollows/Precedes[OrEquals]() 2025-10-14 17:03:48 -04:00
tsmapi.h Update copyright for 2025 2025-01-01 11:21:55 -05:00
tupconvert.h Update copyright for 2025 2025-01-01 11:21:55 -05:00
tupdesc.h Allow NOT NULL constraints to be added as NOT VALID 2025-04-07 19:19:50 +02:00
tupdesc_details.h Update copyright for 2025 2025-01-01 11:21:55 -05:00
tupmacs.h Grab the low-hanging fruit from forcing sizeof(Datum) to 8. 2025-08-13 17:18:22 -04:00
twophase.h Post-commit review fixes for 228c370868. 2025-09-08 06:10:15 +00:00
twophase_rmgr.h Integrate FullTransactionIds deeper into two-phase code 2025-07-07 12:50:40 +09:00
valid.h Update copyright for 2025 2025-01-01 11:21:55 -05:00
visibilitymap.h Eliminate COPY FREEZE use of XLOG_HEAP2_VISIBLE 2025-10-09 16:29:01 -04:00
visibilitymapdefs.h Update copyright for 2025 2025-01-01 11:21:55 -05:00
xact.h Improve comment about snapshot macros 2025-09-11 19:49:57 +02:00
xlog.h Fix unconditional WAL receiver shutdown during stream-archive transition 2025-11-04 10:47:38 +09:00
xlog_internal.h Bump XLOG_PAGE_MAGIC after xl_heap_prune change 2025-10-14 10:13:10 -04:00
xlogarchive.h Update copyright for 2025 2025-01-01 11:21:55 -05:00
xlogbackup.h Update copyright for 2025 2025-01-01 11:21:55 -05:00
xlogdefs.h Fix incorrect LSN format in comment. 2025-08-14 11:12:03 +09:00
xloginsert.h Refactor some repetitive SLRU code 2025-07-07 16:49:19 +02:00
xlogprefetcher.h Update copyright for 2025 2025-01-01 11:21:55 -05:00
xlogreader.h Remove unused data_bufsz from DecodedBkpBlock struct. 2025-10-17 11:28:54 -07:00
xlogrecord.h Update copyright for 2025 2025-01-01 11:21:55 -05:00
xlogrecovery.h Move enum RecoveryTargetAction to xlogrecovery.h 2025-07-23 11:02:13 +02:00
xlogstats.h Fix two typos in xlogstats.h and xlogstats.c 2025-10-10 11:51:45 +09:00
xlogutils.h Update copyright for 2025 2025-01-01 11:21:55 -05:00