postgresql/src/include/access
Michael Paquier 02657c4219 Fix handling of WAL segments ready to be archived during crash recovery
78ea8b5 has fixed an issue related to the recycling of WAL segments on
standbys depending on archive_mode.  However, it has introduced a
regression with the handling of WAL segments ready to be archived during
crash recovery, causing those files to be recycled without getting
archived.

This commit fixes the regression by tracking in shared memory if a live
cluster is either in crash recovery or archive recovery as the handling
of WAL segments ready to be archived is different in both cases (those
WAL segments should not be removed during crash recovery), and by using
this new shared memory state to decide if a segment can be recycled or
not.  Previously, it was not possible to know if a cluster was in crash
recovery or archive recovery as the shared state was able to track only
if recovery was happening or not, leading to the problem.

A set of TAP tests is added to close the gap here, making sure that WAL
segments ready to be archived are correctly handled when a cluster is in
archive or crash recovery with archive_mode set to "on" or "always", for
both standby and primary.

Reported-by: Benoît Lobréau
Author: Jehan-Guillaume de Rorthais
Reviewed-by: Kyotaro Horiguchi, Fujii Masao, Michael Paquier
Discussion: https://postgr.es/m/20200331172229.40ee00dc@firost
Backpatch-through: 9.5
2020-04-24 08:48:45 +09:00
..
amapi.h Phase 3 of pgindent updates. 2017-06-21 15:35:54 -04:00
amvalidate.h Phase 2 of pgindent updates. 2017-06-21 15:19:25 -04:00
attnum.h Phase 2 of pgindent updates. 2017-06-21 15:19:25 -04:00
brin.h Phase 2 of pgindent updates. 2017-06-21 15:19:25 -04:00
brin_internal.h Phase 2 of pgindent updates. 2017-06-21 15:19:25 -04:00
brin_page.h Phase 2 of pgindent updates. 2017-06-21 15:19:25 -04:00
brin_pageops.h Phase 2 of pgindent updates. 2017-06-21 15:19:25 -04:00
brin_revmap.h Phase 2 of pgindent updates. 2017-06-21 15:19:25 -04:00
brin_tuple.h Phase 2 of pgindent updates. 2017-06-21 15:19:25 -04:00
brin_xlog.h Phase 2 of pgindent updates. 2017-06-21 15:19:25 -04:00
bufmask.h For wal_consistency_checking, mask page checksum as well as page LSN. 2017-09-22 14:33:18 -04:00
clog.h Phase 3 of pgindent updates. 2017-06-21 15:35:54 -04:00
commit_ts.h Phase 2 of pgindent updates. 2017-06-21 15:19:25 -04:00
genam.h Improve handling of NULLs in KNN-GiST and KNN-SP-GiST 2019-09-19 21:50:00 +03:00
generic_xlog.h Phase 2 of pgindent updates. 2017-06-21 15:19:25 -04:00
gin.h Phase 2 of pgindent updates. 2017-06-21 15:19:25 -04:00
gin_private.h Rename rbtree.c functions to use "rbt" prefix not "rb" prefix. 2018-11-06 13:25:24 -05:00
ginblock.h Prevent GIN deleted pages from being reclaimed too early 2018-12-13 06:41:04 +03:00
ginxlog.h Fix WAL format incompatibility introduced by backpatching of 52ac6cd2d0 2019-03-24 15:41:32 +03:00
gist.h Phase 2 of pgindent updates. 2017-06-21 15:19:25 -04:00
gist_private.h Revert "Skip WAL for new relfilenodes, under wal_level=minimal." 2020-03-22 09:24:14 -07:00
gistscan.h Phase 2 of pgindent updates. 2017-06-21 15:19:25 -04:00
gistxlog.h Revert "Skip WAL for new relfilenodes, under wal_level=minimal." 2020-03-22 09:24:14 -07:00
hash.h Fix the overrun in hash index metapage for smaller block sizes. 2018-09-06 10:19:51 +05:30
hash_xlog.h Phase 2 of pgindent updates. 2017-06-21 15:19:25 -04:00
heapam.h Revert "Skip WAL for new relfilenodes, under wal_level=minimal." 2020-03-22 09:24:14 -07:00
heapam_xlog.h Perform a lot more sanity checks when freezing tuples. 2017-12-14 18:20:48 -08:00
hio.h Phase 2 of pgindent updates. 2017-06-21 15:19:25 -04:00
htup.h Phase 2 of pgindent updates. 2017-06-21 15:19:25 -04:00
htup_details.h Phase 2 of pgindent updates. 2017-06-21 15:19:25 -04:00
itup.h Phase 2 of pgindent updates. 2017-06-21 15:19:25 -04:00
multixact.h Phase 2 of pgindent updates. 2017-06-21 15:19:25 -04:00
nbtree.h Allow btree comparison functions to return INT_MIN. 2018-10-05 16:01:29 -04:00
nbtxlog.h Fix nbtree page split rmgr desc routine. 2019-09-12 15:45:03 -07:00
parallel.h Mark a few parallelism-related variables with PGDLLIMPORT. 2019-06-03 21:25:43 -04:00
printsimple.h Phase 2 of pgindent updates. 2017-06-21 15:19:25 -04:00
printtup.h Phase 2 of pgindent updates. 2017-06-21 15:19:25 -04:00
reloptions.h Phase 2 of pgindent updates. 2017-06-21 15:19:25 -04:00
relscan.h Phase 2 of pgindent updates. 2017-06-21 15:19:25 -04:00
rewriteheap.h Revert "Skip WAL for new relfilenodes, under wal_level=minimal." 2020-03-22 09:24:14 -07:00
rmgr.h Phase 2 of pgindent updates. 2017-06-21 15:19:25 -04:00
rmgrlist.h hash: Support WAL consistency checking. 2017-03-14 14:58:56 -04:00
sdir.h Phase 2 of pgindent updates. 2017-06-21 15:19:25 -04:00
skey.h Phase 2 of pgindent updates. 2017-06-21 15:19:25 -04:00
slru.h Remove outdated comment 2017-06-30 14:43:05 -04:00
spgist.h Phase 2 of pgindent updates. 2017-06-21 15:19:25 -04:00
spgist_private.h Prevent query-lifespan memory leakage of SP-GiST traversal values. 2018-03-19 23:59:17 -04:00
spgxlog.h Phase 2 of pgindent updates. 2017-06-21 15:19:25 -04:00
stratnum.h Phase 2 of pgindent updates. 2017-06-21 15:19:25 -04:00
subtrans.h Phase 2 of pgindent updates. 2017-06-21 15:19:25 -04:00
sysattr.h Phase 2 of pgindent updates. 2017-06-21 15:19:25 -04:00
timeline.h Phase 2 of pgindent updates. 2017-06-21 15:19:25 -04:00
transam.h Phase 2 of pgindent updates. 2017-06-21 15:19:25 -04:00
tsmapi.h Phase 2 of pgindent updates. 2017-06-21 15:19:25 -04:00
tupconvert.h Phase 2 of pgindent updates. 2017-06-21 15:19:25 -04:00
tupdesc.h Backpatch introduction of TupleDescAttr(tupdesc, i). 2017-08-22 07:46:05 -07:00
tupmacs.h Phase 2 of pgindent updates. 2017-06-21 15:19:25 -04:00
tuptoaster.h Phase 2 of pgindent updates. 2017-06-21 15:19:25 -04:00
twophase.h Mark assorted variables PGDLLIMPORT. 2017-12-05 09:24:05 -05:00
twophase_rmgr.h Phase 2 of pgindent updates. 2017-06-21 15:19:25 -04:00
valid.h Phase 2 of pgindent updates. 2017-06-21 15:19:25 -04:00
visibilitymap.h Phase 2 of pgindent updates. 2017-06-21 15:19:25 -04:00
xact.h Restrict the use of temporary namespace in two-phase transactions 2019-01-18 09:21:58 +09:00
xlog.h Fix handling of WAL segments ready to be archived during crash recovery 2020-04-24 08:48:45 +09:00
xlog_internal.h Fix comment. 2017-08-01 08:00:11 +09:00
xlogdefs.h Phase 2 of pgindent updates. 2017-06-21 15:19:25 -04:00
xloginsert.h Back-patch log_newpage_range(). 2020-03-21 09:38:34 -07:00
xlogreader.h Fix scenario where streaming standby gets stuck at a continuation record. 2018-05-05 01:35:09 +03:00
xlogrecord.h Phase 2 of pgindent updates. 2017-06-21 15:19:25 -04:00
xlogutils.h Post-PG 10 beta1 pgindent run 2017-05-17 16:31:56 -04:00