Skip to content
This repository has been archived by the owner on Nov 18, 2017. It is now read-only.

replace dash with underscore in the replication slotname #50

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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