diff --git a/check_pg_streaming_replication b/check_pg_streaming_replication index 3023d37..ae746a3 100755 --- a/check_pg_streaming_replication +++ b/check_pg_streaming_replication @@ -120,6 +120,12 @@ function psql_get () { echo "$sql"|su - $PG_USER -c "$PSQL_BIN -d "$PG_DB" -w -t -P format=unaligned" } +function psql_master_get () { + sql="$1" + debug "Exec 'echo \"$sql\"|su - $PG_USER -c \"$PSQL_BIN -U $M_USER -h $M_HOST -w -p $M_PORT -d $PG_DB -t -P format=unaligned\"" + echo "$sql"|su - $PG_USER -c "$PSQL_BIN -U $M_USER -h $M_HOST -w -p $M_PORT -d $PG_DB -t -P format=unaligned" +} + function debug() { if [ $DEBUG -eq 1 ] then @@ -211,7 +217,7 @@ then fi # Get current xlog file from master - M_CUR_XLOG="$( echo 'SELECT pg_current_xlog_location()'|su - $PG_USER -c "$PSQL_BIN -U $M_USER -h $M_HOST -p $M_PORT -d $PG_DB -t -P format=unaligned" )" + M_CUR_XLOG="$( psql_master_get 'SELECT pg_current_xlog_location()' )" if [ ! -n "$M_CUR_XLOG" ] then echo "UNKNOWN : Can't retreive current xlog from master server"