From 06bbe2eadc5bf1587870ee3c9a48cb0fc8b4a79f Mon Sep 17 00:00:00 2001 From: Michael Banck Date: Thu, 19 Jan 2023 09:53:17 +0100 Subject: [PATCH] Suppress recurring errors when dropping unknown but active replication slots (#2502) When a replication slot is not registered with Patroni but is active, Patroni would log an error during each HA cycle in certain conditions (after a restart or role change). To avoid this, first check if the replication slot we are about to drop is still active and if so, only log a warning. Otherwise, log the slot we are dropping for informational purposes. Close: #2499 --- patroni/postgresql/slots.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/patroni/postgresql/slots.py b/patroni/postgresql/slots.py index 492d2027..7abe2182 100644 --- a/patroni/postgresql/slots.py +++ b/patroni/postgresql/slots.py @@ -200,10 +200,18 @@ class SlotsHandler(object): def _drop_incorrect_slots(self, cluster, slots, paused): # drop old replication slots which are not presented in desired slots for name in set(self._replication_slots) - set(slots): - if not paused and not self.ignore_replication_slot(cluster, name) and not self.drop_replication_slot(name): - logger.error("Failed to drop replication slot '%s'", name) - self._schedule_load_slots = True - + if not paused and not self.ignore_replication_slot(cluster, name): + if not self.drop_replication_slot(name): + self._schedule_load_slots = True + # Check if slot is still active, this is not considered an error + cursor = self._query(('SELECT 1 FROM pg_catalog.pg_replication_slots WHERE ' + + 'slot_name = %s AND active'), name) + if (cursor.rowcount == 1): + logger.debug("Unable to drop unknown replication slot '%s', slot is still active", name) + else: + logger.error("Failed to drop replication slot '%s'", name) + else: + logger.info("Dropped unknown replication slot '%s'", name) for name, value in slots.items(): if name in self._replication_slots and not compare_slots(value, self._replication_slots[name]): logger.info("Trying to drop replication slot '%s' because value is changing from %s to %s",