1

I have a function block as below which is getting called from somewhere. The call is happening fine but when it's executing any of the below psql check commands eg:

local db_availability_check_88=`psql -h 10.95.187.88 -p 5444 -c "\pset tuples_only" -c "select pg_is_in_recovery;"|grep -v "Tuples"`

The script terminates immediately if the script is unable to communicate to the database via the above psql command. I want thee script to continue its execution. If the connectivity fails it should continue with the next statements.

check_db_status_function () {
    echo "entered function block db_status"
    local db_availability_check_67=`psql -h 10.95.167.87 -p 5444 -c "\pset tuples_only" -c "select pg_is_in_recovery;"|grep -v "Tuples"`
    local db_availability_check_68=`psql -h 10.95.167.88 -p 5444 -c "\pset tuples_only" -c "select pg_is_in_recovery;"|grep -v "Tuples"`
    local db_availability_check_69=`psql -h 10.95.167.89 -p 5444 -c "\pset tuples_only" -c "select pg_is_in_recovery;"|grep -v "Tuples"`

      if [[ ( $a1 = "down" ) && ( $a3 != "primary" ) && ( $db_availability_check_67 = 't' ) ]];
      then
      echo "pgPool services are down on the node:$a2"
      echo "Promoting..."
      /u01/edb/pgpool3.6/bin/pcp_attach_node -w -U pcpuser -h localhost -p 9898 $a0
      fi

The script o/p is as :

Nested block 1
check_db_stat
entered function block db_status
psql.bin: could not connect to server: Connection refused
        Is the server running on host "10.95.167.88" and accepting
        TCP/IP connections on port 5444?

Thanks, Sandeep

shellter
  • 36,525
  • 7
  • 83
  • 90
Sandy
  • 11
  • 3
  • Please let me know if anyone can help on this. – Sandy May 17 '19 at 16:05
  • Not clear to me why this would be happening. To go back to basics, what happens when you run just the bare command `psql -h 10.95.187.88 -p 5444 -c "\pset tuples_only" -c "select pg_is_in_recovery;" ; echo $?` on a failing node? – shellter May 17 '19 at 16:50
  • This will give the same output as mentioned above.. – Sandy May 17 '19 at 19:58
  • yes, and what is printed from the `echo $?` portion? Also, can you look in the underlying system logs and see if there are any errors attributable to this? – shellter May 17 '19 at 20:44
  • did you do `set -e` in your shell script when you shouldn't have? – richyen Oct 09 '19 at 18:02
  • It might actually be more helpful to see the entire script. I tried running your code, and it continues instead of stopping at the first failure – richyen Oct 09 '19 at 18:04

0 Answers0