BUGFIX: pg_drop_replication_slot may not be called if slot is active (#427)

Default value of wal_sender_timeout is 60 seconds while we are trying to remove replication slot after 30 seconds (ttl=30). That means postgres might think that slot is still active and does nothing. Patroni at the same time was thinking that it was removed successfully.

If the drop replication slot query didn't return any single row we must fetch list of existing physical replication slots from postgres on the next iteration of HA loop.

Fixes: issue #425
This commit is contained in:
Alexander Kukushkin
2017-04-18 12:45:24 +02:00
committed by GitHub
parent d39f895082
commit 1c5d5f1dae
2 changed files with 7 additions and 3 deletions
+6 -3
View File
@@ -1181,9 +1181,12 @@ $$""".format(name, ' '.join(options)), name, password, password)
# drop unused slots
for slot in set(self._replication_slots) - slots:
self._query("""SELECT pg_drop_replication_slot(%s)
WHERE EXISTS(SELECT 1 FROM pg_replication_slots
WHERE slot_name = %s AND NOT active)""", slot, slot)
cursor = self._query("""SELECT pg_drop_replication_slot(%s)
WHERE EXISTS(SELECT 1 FROM pg_replication_slots
WHERE slot_name = %s AND NOT active)""", slot, slot)
if cursor.rowcount != 1: # Either slot doesn't exists or it is still active
self._schedule_load_slots = True # schedule load_replication_slots on the next iteration
# create new slots
for slot in slots - set(self._replication_slots):
+1
View File
@@ -19,6 +19,7 @@ class MockCursor(object):
def __init__(self, connection):
self.connection = connection
self.closed = False
self.rowcount = 0
self.results = []
def execute(self, sql, *params):