- Notifications
You must be signed in to change notification settings - Fork4.9k
Commit6672d79
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.com1 parent620ac28 commit6672d79
2 files changed
+19
-5
lines changedLines changed: 8 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
5433 | 5433 |
| |
5434 | 5434 |
| |
5435 | 5435 |
| |
| 5436 | + | |
| 5437 | + | |
| 5438 | + | |
| 5439 | + | |
| 5440 | + | |
| 5441 | + | |
| 5442 | + | |
| 5443 | + | |
5436 | 5444 |
| |
5437 | 5445 |
| |
5438 | 5446 |
| |
|
Lines changed: 11 additions & 5 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
3024 | 3024 |
| |
3025 | 3025 |
| |
3026 | 3026 |
| |
3027 |
| - | |
3028 |
| - | |
3029 |
| - | |
3030 |
| - | |
| 3027 | + | |
| 3028 | + | |
| 3029 | + | |
| 3030 | + | |
| 3031 | + | |
| 3032 | + | |
| 3033 | + | |
| 3034 | + | |
| 3035 | + | |
| 3036 | + | |
3031 | 3037 |
| |
3032 |
| - | |
| 3038 | + | |
3033 | 3039 |
| |
3034 | 3040 |
| |
3035 | 3041 |
| |
|
0 commit comments
Comments
(0)