aboutsummaryrefslogtreecommitdiff
path: root/doc/src
diff options
context:
space:
mode:
authorHeikki Linnakangas <heikki.linnakangas@iki.fi>2012-12-13 19:00:00 +0200
committerHeikki Linnakangas <heikki.linnakangas@iki.fi>2012-12-13 19:17:32 +0200
commitabfd192b1b5ba5216ac4b1f31dcd553106304b19 (patch)
tree9dc145a8f72c500e06ccc779a2d54784ff1681c1 /doc/src
parent527668717a660e67c2a6cfd4e85f7a513f99f6f2 (diff)
downloadpostgresql-abfd192b1b5ba5216ac4b1f31dcd553106304b19.tar.gz
postgresql-abfd192b1b5ba5216ac4b1f31dcd553106304b19.zip
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.
Diffstat (limited to 'doc/src')
-rw-r--r--doc/src/sgml/high-availability.sgml7
-rw-r--r--doc/src/sgml/protocol.sgml77
2 files changed, 70 insertions, 14 deletions
diff --git a/doc/src/sgml/high-availability.sgml b/doc/src/sgml/high-availability.sgml
index 62f72b40ae0..e8342858c9d 100644
--- a/doc/src/sgml/high-availability.sgml
+++ b/doc/src/sgml/high-availability.sgml
@@ -912,10 +912,9 @@ primary_conninfo = 'host=192.168.1.50 port=5432 user=foo password=foopass'
</para>
<para>
- Promoting a cascading standby terminates the immediate downstream replication
- connections which it serves. This is because the timeline becomes different
- between standbys, and they can no longer continue replication. The
- affected standby(s) may reconnect to reestablish streaming replication.
+ If an upstream standby server is promoted to become new master, downstream
+ servers will continue to stream from the new master if
+ <varname>recovery_target_timeline</> is set to <literal>'latest'</>.
</para>
<para>
diff --git a/doc/src/sgml/protocol.sgml b/doc/src/sgml/protocol.sgml
index f87020c9099..e14627c201e 100644
--- a/doc/src/sgml/protocol.sgml
+++ b/doc/src/sgml/protocol.sgml
@@ -1018,14 +1018,21 @@
</para>
<para>
- There is another Copy-related mode called Copy-both, which allows
+ There is another Copy-related mode called copy-both, which allows
high-speed bulk data transfer to <emphasis>and</> from the server.
Copy-both mode is initiated when a backend in walsender mode
executes a <command>START_REPLICATION</command> statement. The
backend sends a CopyBothResponse message to the frontend. Both
the backend and the frontend may then send CopyData messages
- until the connection is terminated. See <xref
- linkend="protocol-replication">.
+ until either end sends a CopyDone message. After the client
+ sends a CopyDone message, the connection goes from copy-both mode to
+ copy-out mode, and the client may not send any more CopyData messages.
+ Similarly, when the server sends a CopyDone message, the connection
+ goes into copy-in mode, and the server may not send any more CopyData
+ messages. After both sides have sent a CopyDone message, the copy mode
+ is terminated, and the backend reverts to the command-processing mode.
+ See <xref linkend="protocol-replication"> for more information on the
+ subprotocol transmitted over copy-both mode.
</para>
<para>
@@ -1350,19 +1357,69 @@ The commands accepted in walsender mode are:
</varlistentry>
<varlistentry>
- <term>START_REPLICATION <replaceable>XXX</>/<replaceable>XXX</></term>
+ <term>TIMELINE_HISTORY <replaceable class="parameter">tli</replaceable></term>
+ <listitem>
+ <para>
+ Requests the server to send over the timeline history file for timeline
+ <replaceable class="parameter">tli</replaceable>. Server replies with a
+ result set of a single row, containing two fields:
+ </para>
+
+ <para>
+ <variablelist>
+ <varlistentry>
+ <term>
+ filename
+ </term>
+ <listitem>
+ <para>
+ Filename of the timeline history file, e.g 00000002.history.
+ </para>
+ </listitem>
+ </varlistentry>
+
+ <varlistentry>
+ <term>
+ content
+ </term>
+ <listitem>
+ <para>
+ Contents of the timeline history file.
+ </para>
+ </listitem>
+ </varlistentry>
+
+ </variablelist>
+ </para>
+ </listitem>
+ </varlistentry>
+
+ <varlistentry>
+ <term>START_REPLICATION <replaceable class="parameter">XXX/XXX</> TIMELINE <replaceable class="parameter">tli</></term>
<listitem>
<para>
Instructs server to start streaming WAL, starting at
- WAL position <replaceable>XXX</>/<replaceable>XXX</>.
+ WAL position <replaceable class="parameter">XXX/XXX</> on timeline
+ <replaceable class="parameter">tli</>.
The server can reply with an error, e.g. if the requested section of WAL
has already been recycled. On success, server responds with a
CopyBothResponse message, and then starts to stream WAL to the frontend.
- WAL will continue to be streamed until the connection is broken;
- no further commands will be accepted. If the WAL sender process is
- terminated normally (during postmaster shutdown), it will send a
- CommandComplete message before exiting. This might not happen during an
- abnormal shutdown, of course.
+ </para>
+
+ <para>
+ If the client requests a timeline that's not the latest, but is part of
+ the history of the server, the server will stream all the WAL on that
+ timeline starting from the requested startpoint, up to the point where
+ the server switched to another timeline. If the client requests
+ streaming at exactly the end of an old timeline, the server responds
+ immediately with CommandComplete without entering COPY mode.
+ </para>
+
+ <para>
+ After streaming all the WAL on a timeline that is not the latest one,
+ the server will end streaming by exiting the COPY mode. When the client
+ acknowledges this by also exiting COPY mode, the server responds with a
+ CommandComplete message, and is ready to accept a new command.
</para>
<para>