From 7bd28250cadc958038de7b5aa6b4a4a985b1ec63 Mon Sep 17 00:00:00 2001 From: Alexander Kukushkin Date: Fri, 17 Sep 2021 14:44:54 +0200 Subject: [PATCH] Skip temporary replication slots while doing slot management (#2055) Starting from v10 `pg_basebackup` creates a temporary replication slot for WAL streaming and Patroni was trying to drop it because the slot name looks unknown. In order to fix it, we skip all temporary slots when querying `pg_stat_replication_slots` view. Another option to solve the problem would be running `pg_basebackup` with `--slot=current_node_name` option, but unfortunately at the moment when `pg_basebackup` is executed, we don't yet know the major version (the `--slot` option was added in v9.6). Ref: https://github.com/zalando/patroni/issues/2046#issuecomment-912521502 --- patroni/postgresql/slots.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/patroni/postgresql/slots.py b/patroni/postgresql/slots.py index 43b7e30c..b5483bff 100644 --- a/patroni/postgresql/slots.py +++ b/patroni/postgresql/slots.py @@ -82,8 +82,9 @@ class SlotsHandler(object): replication_slots = {} extra = ", catalog_xmin, pg_catalog.pg_wal_lsn_diff(confirmed_flush_lsn, '0/0')::bigint"\ if self._postgresql.major_version >= 100000 else "" + skip_temp_slots = ' WHERE NOT temporary' if self._postgresql.major_version >= 100000 else '' cursor = self._query('SELECT slot_name, slot_type, plugin, database, datoid' - '{0} FROM pg_catalog.pg_replication_slots'.format(extra)) + '{0} FROM pg_catalog.pg_replication_slots{1}'.format(extra, skip_temp_slots)) for r in cursor: value = {'type': r[1]} if r[1] == 'logical':