Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commiteb29fa3

Browse files
committed
Prevent WAL corruption after a standby promotion.
When a PostgreSQL instance performing archive recovery but not usingstandby mode is promoted, and the last WAL segment that it attemptedto read ended in a partial record, the previous code would createinvalid WAL on the new timeline. The WAL from the previously timelinewould be copied to the new timeline up until the end of the last validrecord, but instead of beginning to write WAL at immediatelyafterwards, the promoted server would write an overwrite contrecord atthe beginning of the next segment. The end of the previous segmentwould be left as all-zeroes, resulting in failures if anything triedto read WAL from that file.The root of the issue is that ReadRecord() decides whether to setabortedRecPtr and missingContrecPtr based on the value of StandbyMode,but ReadRecord() switches to a new timeline based on the value ofArchiveRecoveryRequested. We shouldn't try to write an overwritecontrecord if we're switching to a new timeline, so change the test inReadRecod() to check ArchiveRecoveryRequested instead.Code fix by Dilip Kumar. Comments by me incorporating suggestedlanguage from Álvaro Herrera. Further review from Kyotaro Horiguchiand Sami Imseih.Discussion:http://postgr.es/m/CAFiTN-t7umki=PK8dT1tcPV=mOUe2vNhHML6b3T7W7qqvvajjg@mail.gmail.comDiscussion:http://postgr.es/m/FB0DEA0B-E14E-43A0-811F-C1AE93D00FF3%40amazon.com
1 parentebe2b40 commiteb29fa3

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

‎src/backend/access/transam/xlog.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5444,6 +5444,14 @@ StartupXLOG(void)
54445444
*/
54455445
if (!XLogRecPtrIsInvalid(missingContrecPtr))
54465446
{
5447+
/*
5448+
* We should only have a missingContrecPtr if we're not switching to
5449+
* a new timeline. When a timeline switch occurs, WAL is copied from
5450+
* the old timeline to the new only up to the end of the last complete
5451+
* record, so there can't be an incomplete WAL record that we need to
5452+
* disregard.
5453+
*/
5454+
Assert(newTLI==endOfRecoveryInfo->lastRecTLI);
54475455
Assert(!XLogRecPtrIsInvalid(abortedRecPtr));
54485456
EndOfLog=missingContrecPtr;
54495457
}

‎src/backend/access/transam/xlogrecovery.c

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3022,12 +3022,18 @@ ReadRecord(XLogPrefetcher *xlogprefetcher, int emode,
30223022
if (record==NULL)
30233023
{
30243024
/*
3025-
* When not in standby mode we find that WAL ends in an incomplete
3026-
* record, keep track of that record. After recovery is done,
3027-
* we'll write a record to indicate to downstream WAL readers that
3028-
* that portion is to be ignored.
3025+
* When we find that WAL ends in an incomplete record, keep track
3026+
* of that record. After recovery is done, we'll write a record to
3027+
* indicate to downstream WAL readers that that portion is to be
3028+
* ignored.
3029+
*
3030+
* However, when ArchiveRecoveryRequested = true, we're going to
3031+
* switch to a new timeline at the end of recovery. We will only
3032+
* copy WAL over to the new timeline up to the end of the last
3033+
* complete record, so if we did this, we would later create an
3034+
* overwrite contrecord in the wrong place, breaking everything.
30293035
*/
3030-
if (!StandbyMode&&
3036+
if (!ArchiveRecoveryRequested&&
30313037
!XLogRecPtrIsInvalid(xlogreader->abortedRecPtr))
30323038
{
30333039
abortedRecPtr=xlogreader->abortedRecPtr;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp