postgresql/src
Robert Haas 6672d79139 Prevent WAL corruption after a standby promotion.
When a PostgreSQL instance performing archive recovery but not using
standby mode is promoted, and the last WAL segment that it attempted
to read ended in a partial record, the previous code would create
invalid WAL on the new timeline. The WAL from the previously timeline
would be copied to the new timeline up until the end of the last valid
record, but instead of beginning to write WAL at immediately
afterwards, the promoted server would write an overwrite contrecord at
the beginning of the next segment. The end of the previous segment
would be left as all-zeroes, resulting in failures if anything tried
to read WAL from that file.

The root of the issue is that ReadRecord() decides whether to set
abortedRecPtr and missingContrecPtr based on the value of StandbyMode,
but ReadRecord() switches to a new timeline based on the value of
ArchiveRecoveryRequested. We shouldn't try to write an overwrite
contrecord if we're switching to a new timeline, so change the test in
ReadRecod() to check ArchiveRecoveryRequested instead.

Code fix by Dilip Kumar. Comments by me incorporating suggested
language from Álvaro Herrera. Further review from Kyotaro Horiguchi
and Sami Imseih.

Discussion: http://postgr.es/m/CAFiTN-t7umki=PK8dT1tcPV=mOUe2vNhHML6b3T7W7qqvvajjg@mail.gmail.com
Discussion: http://postgr.es/m/FB0DEA0B-E14E-43A0-811F-C1AE93D00FF3%40amazon.com
2022-08-29 11:07:37 -04:00
..
backend Prevent WAL corruption after a standby promotion. 2022-08-29 11:07:37 -04:00
bin Remove unneeded null pointer checks before PQfreemem() 2022-08-26 19:16:28 +02:00
common Use SSE2 in is_valid_ascii() where available. 2022-08-26 15:48:49 +07:00
fe_utils Use correct connection for cancellation in frontend's parallel slots 2022-08-27 15:21:31 +09:00
include Add missing padding from MemoryChunk struct 2022-08-29 23:20:25 +12:00
interfaces Remove configure probe for sockaddr_in6 and require AF_INET6. 2022-08-26 10:18:30 +12:00
makefiles solaris: Remove unnecessary gcc / gnu ld vs sun studio differences 2022-08-07 09:36:01 -07:00
pl Be more careful to avoid including system headers after perl.h 2022-08-27 14:45:18 +07:00
port Remove configure probe for sockaddr_in6 and require AF_INET6. 2022-08-26 10:18:30 +12:00
template aix: Remove checks for very old OS versions 2022-08-07 09:36:01 -07:00
test Add optimized functions for linear search within byte arrays 2022-08-26 14:03:39 +07:00
timezone Remove fallbacks for strtoll, strtoull. 2022-08-06 09:59:51 +12:00
tools Improve performance of and reduce overheads of memory management 2022-08-29 17:15:00 +12:00
tutorial Update copyright for 2022 2022-01-07 19:04:57 -05:00
.gitignore
DEVELOPERS
Makefile Remove the option to build thread_test.c outside configure. 2020-10-21 12:08:48 -04:00
Makefile.global.in Remove unused configure variable. 2022-08-18 11:22:13 -04:00
Makefile.shlib aix: Fix SHLIB_EXPORTS reference in VPATH builds 2022-08-24 20:39:46 -07:00
nls-global.mk Fix for make unportability 2022-07-13 09:15:01 +02:00