Skip to content

Commit

Permalink
Fix replication slot maintenance on secondary nodes. (#781)
Browse files Browse the repository at this point in the history
It might happen that a node continues streaming from a secondary after a
failover, and in that case the streaming replication protocol takes care of
maintaining the replication slot. Trying to use pg_replication_slot_advance
would then fail.

This situation currently can arise when a node is in maintenance a failover
happens, where the node in maintenance stays connected to the old-primary,
now repurposed as a secondary.

This situation could also arise when a cascading replication setup is
considered. We don't have direct support for those architectures at the
moment, though that's something of interest for the future.
  • Loading branch information
DimCitus committed Aug 6, 2021
1 parent 27a41bf commit 65458e2
Showing 1 changed file with 1 addition and 0 deletions.
1 change: 1 addition & 0 deletions src/bin/pg_autoctl/pgsql.c
Original file line number Diff line number Diff line change
Expand Up @@ -1704,6 +1704,7 @@ pgsql_replication_slot_maintain(PGSQL *pgsql, NodeAddressArray *nodeArray)
" FROM pg_replication_slots s JOIN nodes USING(slot_name), "
" LATERAL pg_replication_slot_advance(slot_name, lsn) a"
" WHERE nodes.lsn <> '0/0' and nodes.lsn >= s.restart_lsn "
" and not s.active "
"), \n"
"created as ("
"SELECT c.slot_name, c.lsn "
Expand Down

0 comments on commit 65458e2

Please sign in to comment.