How to check if the database ready to connect

@sgotti
We deployment stolon on k8s, use the following script to check if the database ready
until psql -U xx -h xx -d xx -p xx -c ‘\q’; do
sleep 5
done

but after the script pass when we run some other psql command,it may failed.
we though it because not all the proxy are ready when the until script passed
Have a good solution about it?

@snailxr It could be the case that one of the proxies is not yet ready (they’ll converge in proxyCheckInterval). In your case you should just double check at 2*proxyCheckInterval interval.

Anyway every client should retry if something fail for whatever reason.

1 Like

We add readinessProbe to proxy deployment ,so that don’t need to double check at 2*proxyCheckInterval interval.Because the k8s service will not redirect to not ready pods

1 Like

Yeah, a readiness probe of a k8s service or using any other load balancer providing a readiness probe (like keepalived) is a great idea.