From 22bbb4223b3a5825cdaeb5d93cdf69bb63b6e3f1 Mon Sep 17 00:00:00 2001 From: Benjamin Renard Date: Fri, 25 Aug 2017 15:12:05 +0200 Subject: [PATCH] Add -D parameter and retreive master user in recovery.conf file --- 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 78e1a8e..03f9d41 100755 --- a/check_pg_streaming_replication +++ b/check_pg_streaming_replication @@ -26,6 +26,7 @@ fi RECOVERY_CONF_FILENAME=recovery.conf RECOVERY_CONF="" PG_DEFAULT_PORT=5432 +PG_DB=template0 DEBUG=0 @@ -39,13 +40,14 @@ Usage : $0 [-d] [-h] [options] -r recovery_conf Specify Postgres recovery configuration file path (Default : $PG_MAIN/$RECOVERY_CONF_FILENAME) -p pg_port Specify default Postgres master TCP port (Default : $PG_DEFAULT_PORT) + -D dbname Specify DB name on Postgres master to connect on (Default : $PG_DB) -d Debug mode -h Show this message EOF exit 0 } -while getopts "hu:b:m:r:p:d" OPTION +while getopts "hu:b:m:r:p:D:d" OPTION do case $OPTION in u) @@ -63,6 +65,9 @@ do p) PG_DEFAULT_PORT=$OPTARG ;; + D) + PG_DB=$OPTARG + ;; d) DEBUG=1 ;; @@ -170,9 +175,18 @@ then else debug "Master port : $M_PORT" fi + + M_USER=$( echo "$MASTER_CONN_INFOS"|sed 's/^.*user= *\([^ ]*\) *.*$/\1/' ) + if [ ! -n "$M_USER" ] + then + debug "Master user not specify, use default : $PG_USER" + M_USER=$PG_USER + else + debug "Master user : $M_USER" + fi # Get current xlog file from master - M_CUR_XLOG="$( echo 'SELECT pg_current_xlog_location()'|su - $PG_USER -c "$PSQL_BIN -h $M_HOST -p $M_PORT -t -P format=unaligned" )" + 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" )" if [ ! -n "$M_CUR_XLOG" ] then echo "UNKNOWN : Can't retreive current xlog from master server"