diff --git a/patroni/postgresql.py b/patroni/postgresql.py index 185b5caf..4ce4cc51 100644 --- a/patroni/postgresql.py +++ b/patroni/postgresql.py @@ -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): diff --git a/tests/test_postgresql.py b/tests/test_postgresql.py index 7f83b909..4481cb7e 100644 --- a/tests/test_postgresql.py +++ b/tests/test_postgresql.py @@ -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):