From ce1255be324f14c40d5de24b7ecf904b5b2f8def Mon Sep 17 00:00:00 2001 From: Sylvain Desbureaux <37377804+sylvainOL@users.noreply.github.com> Date: Tue, 5 Sep 2023 09:01:56 +0200 Subject: [PATCH] allow to use application name for upgrade 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 --- postgres-appliance/major_upgrade/inplace_upgrade.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/postgres-appliance/major_upgrade/inplace_upgrade.py b/postgres-appliance/major_upgrade/inplace_upgrade.py index c36d5e86f..2130db389 100644 --- a/postgres-appliance/major_upgrade/inplace_upgrade.py +++ b/postgres-appliance/major_upgrade/inplace_upgrade.py @@ -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: