Skip to content

Commit

Permalink
allow to use application name for upgrade
Browse files Browse the repository at this point in the history
Instead of using replica IP address, allow to use replica name in case IP address is not reliable (like when using a service mesh).
This trigger is controller by using an environment variable and default behavior is the previous one

Signed-off-by: Sylvain Desbureaux <[email protected]>
  • Loading branch information
sylvainOL committed Dec 5, 2023
1 parent 4ff0bcb commit 67027a7
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion postgres-appliance/major_upgrade/inplace_upgrade.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,13 +172,15 @@ def ensure_replicas_state(self, cluster):
"""
self.replica_connections = {}
streaming = {a: l for a, l in self.postgresql.query(
("SELECT client_addr, pg_catalog.pg_{0}_{1}_diff(pg_catalog.pg_current_{0}_{1}(),"
("SELECT client_addr, application_name, pg_catalog.pg_{0}_{1}_diff(pg_catalog.pg_current_{0}_{1}(),"
" COALESCE(replay_{1}, '0/0'))::bigint FROM pg_catalog.pg_stat_replication")
.format(self.postgresql.wal_name, self.postgresql.lsn_name))}

def ensure_replica_state(member):
ip = member.conn_kwargs().get('host')
lag = streaming.get(ip)
if os.getenv('USE_APPLICATION_NAME_IN_UPGRADE'):
lag = streaming.get(member.name)
if lag is None:
return logger.error('Member %s is not streaming from the primary', member.name)
if lag > 16*1024*1024:
Expand Down

0 comments on commit 67027a7

Please sign in to comment.