postgresql/src/include
Michael Paquier 9eff116539 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:55 +09:00
..
access Fix handling of WAL segments ready to be archived during crash recovery 2020-04-24 08:48:55 +09:00
bootstrap pgindent run for 9.5 2015-05-23 21:35:49 -04:00
catalog Fix possible crash during FATAL exit from reindexing. 2020-04-21 15:58:43 -04:00
commands Mark assorted variables PGDLLIMPORT. 2017-12-05 09:30:57 -05:00
common Fix integer-overflow problems in interval comparison. 2017-04-05 23:51:28 -04:00
datatype Define integer limits independently from the system definitions. 2015-04-02 17:43:35 +02:00
executor Fix failure with initplans used conditionally during EvalPlanQual rechecks. 2018-09-15 13:42:34 -04:00
fe_utils Empty search_path in Autovacuum and non-psql/pgbench clients. 2018-02-26 07:39:48 -08:00
foreign Allow foreign and custom joins to handle EvalPlanQual rechecks. 2015-12-08 12:54:33 -05:00
lib Revert "Permit dump/reload of not-too-large >1GB tuples" 2016-12-06 12:45:49 -03:00
libpq Fix detection of passwords hashed with MD5 2019-04-24 09:05:30 +09:00
mb Teach UtfToLocal/LocalToUtf to support algorithmic encoding conversions. 2015-05-14 22:27:12 -04:00
nodes Revert "Skip WAL for new relfilenodes, under wal_level=minimal." 2020-03-22 09:24:15 -07:00
optimizer Fix incorrect handling of join clauses pushed into parameterized paths. 2018-04-19 15:49:12 -04:00
parser Require the schema qualification in pg_temp.type_name(arg). 2019-08-05 07:48:45 -07:00
port Replace xlc __fetch_and_add() with inline asm. 2019-09-13 19:34:19 -07:00
portability Use mmap MAP_NOSYNC option to limit shared memory writes 2015-03-21 22:06:19 -04:00
postmaster Mark assorted variables PGDLLIMPORT. 2017-12-05 09:30:57 -05:00
regex Suppress compiler warnings about useless comparison of unsigned to zero. 2016-02-15 17:11:52 -05:00
replication Set ReorderBufferTXN->final_lsn more eagerly 2020-01-17 18:00:39 -03:00
rewrite Defend against self-referential views in relation_is_updatable(). 2019-11-21 16:21:44 -05:00
snowball Update copyright for 2015 2015-01-06 11:43:47 -05:00
storage Revert "Skip WAL for new relfilenodes, under wal_level=minimal." 2020-03-22 09:24:15 -07:00
tcop Fix event triggers for partitioned tables 2018-10-06 19:17:46 -03:00
tsearch Fix statically allocated struct with FLEXIBLE_ARRAY_MEMBER member. 2015-02-20 17:50:18 -05:00
utils Preserve clustered index after rewrites with ALTER TABLE 2020-04-06 11:06:07 +09:00
.gitignore Autoconfiscate selection of 64-bit int type for 64-bit large object API. 2012-10-07 21:52:43 -04:00
c.h Fix integer-overflow edge case detection in interval_mul and pgbench. 2019-11-07 11:23:04 -05:00
fmgr.h Revert addition of PGDLLEXPORT in PG_FUNCTION_INFO_V1 macro. 2016-10-12 18:02:03 -04:00
funcapi.h Avoid holding a directory FD open across assorted SRF calls. 2020-03-16 21:05:29 -04:00
getaddrinfo.h Update copyright for 2015 2015-01-06 11:43:47 -05:00
getopt_long.h Update copyright for 2015 2015-01-06 11:43:47 -05:00
Makefile Empty search_path in Autovacuum and non-psql/pgbench clients. 2018-02-26 07:39:48 -08:00
miscadmin.h Mark assorted variables PGDLLIMPORT. 2017-12-05 09:30:57 -05:00
pg_config.h.in Avoid thread-safety problem in ecpglib. 2019-01-21 23:18:58 -05:00
pg_config.h.win32 Stamp 9.5.21. 2020-02-10 17:23:16 -05:00
pg_config_ext.h.in Autoconfiscate selection of 64-bit int type for 64-bit large object API. 2012-10-07 21:52:43 -04:00
pg_config_ext.h.win32 Autoconfiscate selection of 64-bit int type for 64-bit large object API. 2012-10-07 21:52:43 -04:00
pg_config_manual.h Further reduce the number of semaphores used under --disable-spinlocks. 2016-04-18 13:33:07 -04:00
pg_getopt.h Use our own getopt() on OpenBSD. 2019-01-18 15:06:26 -05:00
pg_trace.h Update copyright for 2015 2015-01-06 11:43:47 -05:00
pgstat.h Add GUC variables for stat tracking and timeout as PGDLLIMPORT 2020-01-21 13:47:13 +09:00
pgtar.h Adopt the GNU convention for handling tar-archive members exceeding 8GB. 2015-11-21 20:21:32 -05:00
pgtime.h Mark assorted variables PGDLLIMPORT. 2017-12-05 09:30:57 -05:00
port.h Fix misc typos in comments. 2019-01-23 13:46:51 +02:00
postgres.h Adjust DatumGetBool macro, this time for sure. 2016-04-28 11:51:08 -04:00
postgres_ext.h pgindent run for 9.4 2014-05-06 12:12:18 -04:00
postgres_fe.h Update copyright for 2015 2015-01-06 11:43:47 -05:00
rusagestub.h Update copyright for 2015 2015-01-06 11:43:47 -05:00
windowapi.h Update copyright for 2015 2015-01-06 11:43:47 -05:00