+

Use PG_DB also on slave and use PG_USER as default value.

Benjamin Renard [2017-08-25 14:18:51]
Use PG_DB also on slave and use PG_USER as default value.
Filename
check_pg_streaming_replication
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() {
ViewGit