1

我有一个如下的功能块,它从某处被调用。调用正常,但是当它执行以下任何 psql 检查命令时,例如:

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"`

如果脚本无法通过上述 psql 命令与数据库通信,则脚本会立即终止。我希望你的脚本继续执行。如果连接失败,则应继续执行下一条语句。

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

脚本 o/p 如下:

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?

谢谢,桑迪普

4

0 回答 0