From a674949d93e240a29e91ccb7ade03beae3bb7ac3 Mon Sep 17 00:00:00 2001 From: Benjamin Renard Date: Mon, 3 Jun 2024 15:18:56 +0200 Subject: [PATCH] Use cluster_name as default application name on PG 12 and later --- check_pg_streaming_replication | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/check_pg_streaming_replication b/check_pg_streaming_replication index c8a222d..680aee7 100755 --- a/check_pg_streaming_replication +++ b/check_pg_streaming_replication @@ -315,8 +315,22 @@ then M_APP_NAME=$( echo "$MASTER_CONN_INFOS"| grep 'application_name=' | sed "s/^.*application_name=[ \'\"]*\([^ \'\"]\+\)[ \'\"]*.*$/\1/" ) if [ ! -n "$M_APP_NAME" ] then - debug "Master application name not specified, use default: $PG_DEFAULT_APP_NAME" - M_APP_NAME=$PG_DEFAULT_APP_NAME + if [ $PG_VERSION -ge 12 ] + then + debug "Master application name not specified, use cluster_name if defined" + CLUSTER_NAME=$( psql_get "SELECT current_setting('cluster_name')" ) + debug "Cluster name: $CLUSTER_NAME" + if [ -n "$CLUSTER_NAME" ] + then + M_APP_NAME=$CLUSTER_NAME + else + debug "Cluster name not defined, use default: $PG_DEFAULT_APP_NAME" + M_APP_NAME=$PG_DEFAULT_APP_NAME + fi + else + debug "Master application name not specified, use default: $PG_DEFAULT_APP_NAME" + M_APP_NAME=$PG_DEFAULT_APP_NAME + fi else debug "Master application name: $M_APP_NAME" fi