Skip to content
This repository has been archived by the owner on Dec 19, 2022. It is now read-only.

Commit

Permalink
replace dash with underscore in the replication slotname
Browse files Browse the repository at this point in the history
  • Loading branch information
Claus Riegg committed Nov 17, 2017
1 parent 5385850 commit a0ebe86
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
2 changes: 1 addition & 1 deletion governor.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def run(config):
for node in etcd.get_client_path("/members?recursive=true")["node"]["nodes"]:
member = node["key"].split('/')[-1]
if member != postgresql.name:
postgresql.query("DO LANGUAGE plpgsql $$DECLARE somevar VARCHAR; BEGIN SELECT slot_name INTO somevar FROM pg_replication_slots WHERE slot_name = '%(slot)s' LIMIT 1; IF NOT FOUND THEN PERFORM pg_create_physical_replication_slot('%(slot)s'); END IF; END$$;" % {"slot": member})
postgresql.query("DO LANGUAGE plpgsql $$DECLARE somevar VARCHAR; BEGIN SELECT slot_name INTO somevar FROM pg_replication_slots WHERE slot_name = '%(slot)s' LIMIT 1; IF NOT FOUND THEN PERFORM pg_create_physical_replication_slot('%(slot)s'); END IF; END$$;" % {"slot": postgresql.replication_slot_name(member)})
etcd.touch_member(postgresql.name, postgresql.connection_string)

time.sleep(config["loop_wait"])
Expand Down
5 changes: 2 additions & 3 deletions helpers/postgresql.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,7 @@ def is_healthiest_node(self, state_store):
continue
return True

def replication_slot_name(self):
member = os.environ.get("MEMBER")
def replication_slot_name(self, member):
(member, _) = re.subn(r'[^a-z0-9]+', r'_', member)
return member

Expand All @@ -183,7 +182,7 @@ def write_recovery_conf(self, leader_hash):
standby_mode = 'on'
primary_slot_name = '%(recovery_slot)s'
recovery_target_timeline = 'latest'
""" % {"recovery_slot": self.name})
""" % {"recovery_slot": self.replication_slot_name(self.name)})
if leader_hash is not None:
leader = urlparse(leader_hash["address"])
f.write("""
Expand Down

0 comments on commit a0ebe86

Please sign in to comment.