From 67027a7274045b3cb325ea65315d6aa63dfd24e5 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 Signed-off-by: Sylvain Desbureaux --- postgres-appliance/major_upgrade/inplace_upgrade.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/postgres-appliance/major_upgrade/inplace_upgrade.py b/postgres-appliance/major_upgrade/inplace_upgrade.py index 2d4ade477..c4dd4c759 100644 --- a/postgres-appliance/major_upgrade/inplace_upgrade.py +++ b/postgres-appliance/major_upgrade/inplace_upgrade.py @@ -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: