From: | Robert Haas <rhaas(at)postgresql(dot)org> |
---|---|
To: | pgsql-committers(at)lists(dot)postgresql(dot)org |
Subject: | pgsql: Prevent WAL corruption after a standby promotion. |
Date: | 2022-08-29 16:31:43 |
Message-ID: | E1oShfq-000Tyv-PS@gemulon.postgresql.org |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-committers |
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
Branch
------
master
Details
-------
https://git.postgresql.org/pg/commitdiff/6672d7913929b82ec723a54381773d9cdc20fe9d
Modified Files
--------------
src/backend/access/transam/xlog.c | 8 ++++++++
src/backend/access/transam/xlogrecovery.c | 16 +++++++++++-----
2 files changed, 19 insertions(+), 5 deletions(-)
From | Date | Subject | |
---|---|---|---|
Next Message | Robert Haas | 2022-08-29 16:39:41 | pgsql: Remove stray "the". |
Previous Message | Robert Haas | 2022-08-29 14:16:54 | pgsql: docs: Fix up some out-of-date references to INHERIT/NOINHERIT. |