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
  • Loading branch information
sylvainOL authored Sep 5, 2023
1 parent b0e624d commit ce1255b
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions postgres-appliance/major_upgrade/inplace_upgrade.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,14 +170,19 @@ def ensure_replicas_state(self, cluster):
to all of them and puts into the `self.replica_connections` dict for a future usage.
"""
self.replica_connections = {}
selector = "client_addr"
if os.getenv('USE_APPLICATION_NAME_IN_UPGRADE'):
selector = "application_name"
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 {2}, 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))}
.format(self.postgresql.wal_name, self.postgresql.lsn_name, selector))}

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 ce1255b

Please sign in to comment.