#! /bin/sh
psql=/usr/pgsql-16/bin/psql
DATADIR_BASE=/var/volum/RockyLinux9/16/V4_2_STABLE/src/test/regression/tests/017.node_0_is_down/testdir
PGSUPERUSER=postgres

main_db_cluster=$1
recovery_node_host_name=$2
DEST_CLUSTER=$3
PORT=$4

log=$DATADIR_BASE/log/recovery.log
export PGHOST=localhost
# Force to flush current value of sequences to xlog 
$psql -q -p $PORT -t -c 'SELECT datname FROM pg_database WHERE NOT datistemplate AND datallowconn' template1|
while read i
do
  if [ "$i" != "" ];then
    $psql -p $PORT -c "SELECT setval(oid, nextval(oid)) FROM pg_class WHERE relkind = 'S'" $i
  fi
done

$psql -p $PORT -c "SELECT pgpool_switch_xlog('/var/volum/RockyLinux9/16/V4_2_STABLE/src/test/regression/tests/017.node_0_is_down/testdir/archivedir/`basename $1`')" template1
