From 5ca5dacaa9b5505ac6fe781f71f93c6761f92ecf Mon Sep 17 00:00:00 2001 From: Alexander Kukushkin Date: Wed, 29 Aug 2018 11:30:01 +0200 Subject: [PATCH] Immediately reserve LSN on upon creation of replication slot (#783) This feature is available starting from 9.6 --- patroni/postgresql.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/patroni/postgresql.py b/patroni/postgresql.py index 8498d76e..aecc8040 100644 --- a/patroni/postgresql.py +++ b/patroni/postgresql.py @@ -1560,11 +1560,13 @@ $$""".format(name, ' '.join(options)), name, password, password) 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 + immediately_reserve = ', true' if self._major_version >= 90600 else '' + # create new slots for slot in slots - set(self._replication_slots): - self._query("""SELECT pg_create_physical_replication_slot(%s) + self._query("""SELECT pg_create_physical_replication_slot(%s{0}) WHERE NOT EXISTS (SELECT 1 FROM pg_replication_slots - WHERE slot_name = %s)""", slot, slot) + WHERE slot_name = %s)""".format(immediately_reserve), slot, slot) self._replication_slots = slots except Exception: