Add -D parameter and retreive master user in recovery.conf file
Benjamin Renard

Benjamin Renard commited on 2017-08-25 13:12:05
Showing 1 changed files, with 16 additions and 2 deletions.

... ...
@@ -26,6 +26,7 @@ fi
26 26
 RECOVERY_CONF_FILENAME=recovery.conf
27 27
 RECOVERY_CONF=""
28 28
 PG_DEFAULT_PORT=5432
29
+PG_DB=template0
29 30
 
30 31
 DEBUG=0
31 32
 
... ...
@@ -39,13 +40,14 @@ Usage : $0 [-d] [-h] [options]
39 40
 	-r recovery_conf	Specify Postgres recovery configuration file path
40 41
 				(Default : $PG_MAIN/$RECOVERY_CONF_FILENAME)
41 42
 	-p pg_port		Specify default Postgres master TCP port (Default : $PG_DEFAULT_PORT)
43
+	-D dbname		Specify DB name on Postgres master to connect on (Default : $PG_DB)
42 44
 	-d			Debug mode
43 45
 	-h 			Show this message
44 46
 EOF
45 47
 	exit 0
46 48
 }
47 49
 
48
-while getopts "hu:b:m:r:p:d" OPTION
50
+while getopts "hu:b:m:r:p:D:d" OPTION
49 51
 do
50 52
 	case $OPTION in
51 53
 		u)
... ...
@@ -63,6 +65,9 @@ do
63 65
 		p)
64 66
 			PG_DEFAULT_PORT=$OPTARG
65 67
 		;;
68
+		D)
69
+			PG_DB=$OPTARG
70
+		;;
66 71
 		d)
67 72
 			DEBUG=1
68 73
 		;;
... ...
@@ -171,8 +176,17 @@ then
171 176
 		debug "Master port : $M_PORT"
172 177
 	fi
173 178
 
179
+	M_USER=$( echo "$MASTER_CONN_INFOS"|sed 's/^.*user= *\([^ ]*\) *.*$/\1/' )
180
+	if [ ! -n "$M_USER" ]
181
+	then
182
+		debug "Master user not specify, use default : $PG_USER"
183
+		M_USER=$PG_USER
184
+	else
185
+		debug "Master user : $M_USER"
186
+	fi
187
+	
174 188
 	# Get current xlog file from master
175
-	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" )"
189
+	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" )"
176 190
 	if [ ! -n "$M_CUR_XLOG" ]
177 191
 	then
178 192
 		echo "UNKNOWN : Can't retreive current xlog from master server"
179 193