Thread: pgsql: Enable logical slots to follow timeline switches

pgsql: Enable logical slots to follow timeline switches

From
Alvaro Herrera
Date:
Enable logical slots to follow timeline switches

When decoding from a logical slot, it's necessary for xlog reading to be
able to read xlog from historical (i.e. not current) timelines;
otherwise, decoding fails after failover, because the archives are in
the historical timeline.  This is required to make "failover logical
slots" possible; it currently has no other use, although theoretically
it could be used by an extension that creates a slot on a standby and
continues to replay from the slot when the standby is promoted.

This commit includes a module in src/test/modules with functions to
manipulate the slots (which is not otherwise possible in SQL code) in
order to enable testing, and a new test in src/test/recovery to ensure
that the behavior is as expected.

Author: Craig Ringer
Reviewed-By: Oleksii Kliukin, Andres Freund, Petr Jelínek

Branch
------
master

Details
-------
http://git.postgresql.org/pg/commitdiff/24c5f1a103ce6656a5cb430d9a996c34e61ab2a5

Modified Files
--------------
src/backend/access/transam/xlogreader.c            |   9 +
src/backend/access/transam/xlogutils.c             | 244 +++++++++++++++--
src/backend/replication/logical/logicalfuncs.c     |  17 +-
src/include/access/xlogreader.h                    |  18 ++
src/test/modules/Makefile                          |   1 +
src/test/modules/test_slot_timelines/.gitignore    |   3 +
src/test/modules/test_slot_timelines/Makefile      |  22 ++
src/test/modules/test_slot_timelines/README        |  19 ++
.../expected/load_extension.out                    |  19 ++
.../test_slot_timelines/sql/load_extension.sql     |   7 +
.../test_slot_timelines--1.0.sql                   |  16 ++
.../test_slot_timelines/test_slot_timelines.c      | 133 +++++++++
.../test_slot_timelines/test_slot_timelines.conf   |   2 +
.../test_slot_timelines.control                    |   5 +
src/test/recovery/Makefile                         |   2 +
.../recovery/t/006_logical_decoding_timelines.pl   | 304 +++++++++++++++++++++
16 files changed, 790 insertions(+), 31 deletions(-)


Re: pgsql: Enable logical slots to follow timeline switches

From
Tom Lane
Date:
Alvaro Herrera <alvherre@alvh.no-ip.org> writes:
> Enable logical slots to follow timeline switches

Buildfarm doesn't like this one bit :-(

            regards, tom lane


Re: pgsql: Enable logical slots to follow timeline switches

From
Alvaro Herrera
Date:
Tom Lane wrote:
> Alvaro Herrera <alvherre@alvh.no-ip.org> writes:
> > Enable logical slots to follow timeline switches
>
> Buildfarm doesn't like this one bit :-(

Argh, forgot the alternate expected file when the needed feature is
disabled.  Will fix.

--
Álvaro Herrera                http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services


Re: pgsql: Enable logical slots to follow timeline switches

From
Michael Paquier
Date:
On Thu, Mar 31, 2016 at 8:45 AM, Alvaro Herrera
<alvherre@2ndquadrant.com> wrote:
> Tom Lane wrote:
>> Alvaro Herrera <alvherre@alvh.no-ip.org> writes:
>> > Enable logical slots to follow timeline switches
>>
>> Buildfarm doesn't like this one bit :-(
>
> Argh, forgot the alternate expected file when the needed feature is
> disabled.  Will fix.

hamster complains here:
http://buildfarm.postgresql.org/cgi-bin/show_log.pl?nm=hamster&dt=2016-03-31%2016%3A00%3A06
[...]
# Copying slots to replica
after_basebackup|test_decoding||547|0/5000060|0/5000098
# Copying slot 'after_basebackup','test_decoding',NULL,'547','0/5000060','0/5000098'
connection error: 'psql:<stdin>:1: server closed the connection unexpectedly
This probably means the server terminated abnormally
before or while processing the request.
psql:<stdin>:1: connection to server was lost'
--
Michael