echo"Query \"$query\" didn't return expected result $result after $timeout seconds"
exit 1
fi
sleep 1
done
}
function wait_all_streaming(){
wait_query "$1""SELECT COUNT(*) FROM pg_stat_replication WHERE application_name LIKE 'spilo_'" 2
}
function wait_zero_lag(){
wait_query "$1""SELECT COUNT(*) FROM pg_stat_replication WHERE application_name LIKE 'spilo_' AND pg_catalog.pg_xlog_location_diff(pg_catalog.pg_current_xlog_location(), COALESCE(replay_location, '0/0')) < 16*1024*1024" 2