Skip site navigation (1) Skip section navigation (2)

pgsql: Allow a streaming replication standby to follow a timelineswitc

From: Heikki Linnakangas <heikki(dot)linnakangas(at)iki(dot)fi>
To: pgsql-committers(at)postgresql(dot)org
Subject: pgsql: Allow a streaming replication standby to follow a timelineswitc
Date: 2012-12-13 17:19:36
Message-ID: E1TjCRc-00084r-1H@gemulon.postgresql.org (view raw or flat)
Thread:
Lists: pgsql-committerspgsql-general
Allow a streaming replication standby to follow a timeline switch.

Before this patch, streaming replication would refuse to start replicating
if the timeline in the primary doesn't exactly match the standby. The
situation where it doesn't match is when you have a master, and two
standbys, and you promote one of the standbys to become new master.
Promoting bumps up the timeline ID, and after that bump, the other standby
would refuse to continue.

There's significantly more timeline related logic in streaming replication
now. First of all, when a standby connects to primary, it will ask the
primary for any timeline history files that are missing from the standby.
The missing files are sent using a new replication command TIMELINE_HISTORY,
and stored in standby's pg_xlog directory. Using the timeline history files,
the standby can follow the latest timeline present in the primary
(recovery_target_timeline='latest'), just as it can follow new timelines
appearing in an archive directory.

START_REPLICATION now takes a TIMELINE parameter, to specify exactly which
timeline to stream WAL from. This allows the standby to request the primary
to send over WAL that precedes the promotion. The replication protocol is
changed slightly (in a backwards-compatible way although there's little hope
of streaming replication working across major versions anyway), to allow
replication to stop when the end of timeline reached, putting the walsender
back into accepting a replication command.

Many thanks to Amit Kapila for testing and reviewing various versions of
this patch.

Branch
------
master

Details
-------
http://git.postgresql.org/pg/commitdiff/abfd192b1b5ba5216ac4b1f31dcd553106304b19

Modified Files
--------------
doc/src/sgml/high-availability.sgml                |    7 +-
doc/src/sgml/protocol.sgml                         |   77 +++-
src/backend/access/transam/timeline.c              |   83 +++
src/backend/access/transam/xlog.c                  |   55 +-
src/backend/access/transam/xlogfuncs.c             |    4 +-
src/backend/postmaster/postmaster.c                |   21 -
src/backend/postmaster/startup.c                   |    2 +
src/backend/replication/basebackup.c               |   21 +-
.../libpqwalreceiver/libpqwalreceiver.c            |  202 +++++--
src/backend/replication/repl_gram.y                |   47 ++-
src/backend/replication/repl_scanner.l             |   10 +
src/backend/replication/walreceiver.c              |  472 +++++++++++++---
src/backend/replication/walreceiverfuncs.c         |   90 +++-
src/backend/replication/walsender.c                |  587 +++++++++++++++----
src/include/access/timeline.h                      |    1 +
src/include/access/xlog.h                          |    4 +-
src/include/nodes/nodes.h                          |    1 +
src/include/nodes/replnodes.h                      |   12 +
src/include/replication/walreceiver.h              |   52 ++-
src/include/replication/walsender.h                |    1 -
src/include/replication/walsender_private.h        |    2 +-
src/interfaces/libpq/fe-exec.c                     |    8 +-
src/interfaces/libpq/fe-protocol3.c                |    7 +-
23 files changed, 1396 insertions(+), 370 deletions(-)


Responses

pgsql-committers by date

Next:From: Peter EisentrautDate: 2012-12-14 04:01:27
Subject: pgsql: doc: Improve search_path mentions in index
Previous:From: Heikki LinnakangasDate: 2012-12-13 13:05:56
Subject: pgsql: Make xlog_internal.h includable in frontend context.

pgsql-general by date

Next:From: Amitabh KantDate: 2012-12-13 17:42:10
Subject: Re: initdb error
Previous:From: Paul JungwirthDate: 2012-12-13 17:18:21
Subject: Re: JDBC to load UTF8@psql to latin1@mysql

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group