pgsql: Fix more issues with cascading replication and timeline switches - Mailing list pgsql-committers

From Heikki Linnakangas
Subject pgsql: Fix more issues with cascading replication and timeline switches
Date
Msg-id E1TxvYS-0006c4-GJ@gemulon.postgresql.org
Whole thread Raw
List pgsql-committers
Fix more issues with cascading replication and timeline switches.

When a standby server follows the master using WAL archive, and it chooses
a new timeline (recovery_target_timeline='latest'), it only fetches the
timeline history file for the chosen target timeline, not any other history
files that might be missing from pg_xlog. For example, if the current
timeline is 2, and we choose 4 as the new recovery target timeline, the
history file for timeline 3 is not fetched, even if it's part of this
server's history. That's enough for the standby itself - the history file
for timeline 4 includes timeline 3 as well - but if a cascading standby
server wants to recover to timeline 3, it needs the history file. To fix,
when a new recovery target timeline is chosen, try to copy any missing
history files from the archive to pg_xlog between the old and new target
timeline.

A second similar issue was with the WAL files. When a standby recovers from
archive, and it reaches a segment that contains a switch to a new timeline,
recovery fetches only the WAL file labelled with the new timeline's ID. The
file from the new timeline contains a copy of the WAL from the old timeline
up to the point where the switch happened, and recovery recovers it from the
new file. But in streaming replication, walsender only tries to read it
from the old timeline's file. To fix, change walsender to read it from the
new file, so that it behaves the same as recovery in that sense, and doesn't
try to open the possibly nonexistent file with the old timeline's ID.

Branch
------
master

Details
-------
http://git.postgresql.org/pg/commitdiff/990fe3c4edfdabf4f56aa9a403a11f53006d0dd7

Modified Files
--------------
src/backend/access/transam/timeline.c       |   22 ++++++++++
src/backend/access/transam/xlog.c           |   22 ++++++++++-
src/backend/replication/walsender.c         |   57 ++++++++++++++++++++++----
src/include/access/timeline.h               |    1 +
src/include/replication/walsender_private.h |    1 -
5 files changed, 92 insertions(+), 11 deletions(-)


pgsql-committers by date:

Previous
From: Tom Lane
Date:
Subject: Re: pgsql: Fix a few small bugs in yesterday's event trigger patch.
Next
From: Andrew Dunstan
Date:
Subject: pgsql: Gitignore vcxproj files.