:
set -x

PGDT=/path_to_data_dir

EXIT="exit 0"

if [ "$1" = "recovery" ]; then

	psql -c "SELECT pg_wal_replay_resume();" postgres

	date +%Y/%m/%d_%H:%M:%S.%3N

	pg_ctl promote -D ${PGDT}

	set +x

	date +%Y/%m/%d_%H:%M:%S.%3N

	while [ 1 ]
	do
		RS=`psql -Atc "select pg_is_in_recovery();" postgres`		

		if [ ${RS} = "f" ]; then
			break
		fi
	done

	date +%Y/%m/%d_%H:%M:%S.%3N

	set -x

	${EXIT}
fi
