I intend to backport this to 9.4 and 9.5 (though of course not for mainline submission!).
Patch 1: add support for timeline following in logical decoding.
This is necessary to make failover slots useful. Otherwise decoding from a slot will fail after failover because the server tries to read WAL with ThisTimeLineID but the needed archives are on a historical timeline. While the smallest part of the patch series this was the most complex.
Patch 2: Failover slots core
* Add WAL logging and redo for failover slots
* copy pg_replslot/ in pg_basebackup
* drop non-failover slots on archive recovery startup
* expand the amount of WAL copied by pg_basebackup so failover slots are usable after restore
* if a failover slot is created on the primary with the same name as an
existing non-failover slot on replica(s), kill any client connected to the
replica's slot and drop the replica's slot during redo
* Adds a new backup label entry MIN FAILOVER SLOT LSN to generated
backup label files if failover slots are present. This allows utilities like
pgbarman, omnipitr, etc to know to retain more WAL to preserve the
function of failover slots.
* Return a lower LSN from pg_start_backup() and BASE_BACKUP
if needed to ensure that tools copy the extra WAL required by failover
slots during a base backup.
Relies on timeline following for logical decoding slots to be useful.
Does not add UI (function arguments, walsender syntax, changes to views, etc) to expose failover slots to users. They can only be used by extensions that call ReplicationSlotCreate directly.
Patch 3: User interface for failover slots
The 3rd patch adds the UI to expose failover slots to the user:
- A 'failover' boolean argument, default false, to pg_create_physical_replication_slot(...) and pg_create_logical_replication_slot(...)
- A new FAILOVER option to PG_CREATE_REPLICATION_SLOT on the walsender protocol
- A new 'failover' boolean column in pg_catalog.pg_replication_slots
- SGML documentation changes for the new options and for failover slots in general
Limited tests are also added in this patch since not much of this is really testable by pg_regress. I've attached my local test script in case it's of interest/use to anyone.