From d8a4cfac5191a6bc20eeb210ed699dd0fc41a2c0 Mon Sep 17 00:00:00 2001 From: Benjamin Renard Date: Fri, 25 Aug 2017 16:18:51 +0200 Subject: [PATCH] Use PG_DB also on slave and use PG_USER as default value. --- check_pg_streaming_replication | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/check_pg_streaming_replication b/check_pg_streaming_replication index 03f9d41..2c13a0a 100755 --- a/check_pg_streaming_replication +++ b/check_pg_streaming_replication @@ -26,7 +26,7 @@ fi RECOVERY_CONF_FILENAME=recovery.conf RECOVERY_CONF="" PG_DEFAULT_PORT=5432 -PG_DB=template0 +PG_DB="" DEBUG=0 @@ -40,7 +40,7 @@ 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 dbname Specify DB name on Postgres master/slave to connect on (Default : PG_USER) -d Debug mode -h Show this message EOF @@ -97,8 +97,11 @@ id "$PG_USER" > /dev/null 2>&1 # Check PG_DEFAULT_PORT [ $( echo "$PG_DEFAULT_PORT"|grep -c -E '^[0-9]*$' ) -ne 1 ] && "UNKNOWN : Postgres default master TCP port must be an integer." && exit 3 +# If PG_DB is not provided with -D parameter, use PG_USER as default value +[ -z "$PB_DB" ] && PG_DB="$PG_USER" + function psql_get () { - echo "$1"|su - $PG_USER -c "$PSQL_BIN -t -P format=unaligned" + echo "$1"|su - $PG_USER -c "$PSQL_BIN -d "$PG_DB" -t -P format=unaligned" } function debug() {