JohnLonganecker, Author at Stark & Wayne https://www.starkandwayne.com/blog/author/johnlonganecker/ Cloud-Native Consultants Thu, 30 Sep 2021 15:49:10 +0000 en-US hourly 1 https://wordpress.org/?v=6.0.3 https://www.starkandwayne.com/wp-content/uploads/2021/04/cropped-SW_Logos__shield_blue_on_transparent_with_border-32x32.png JohnLonganecker, Author at Stark & Wayne https://www.starkandwayne.com/blog/author/johnlonganecker/ 32 32 How to know when your Postgres Service is ready https://www.starkandwayne.com/blog/how-to-know-when-your-postgres-service-is-ready/ Mon, 13 Feb 2017 23:59:07 +0000 https://www.starkandwayne.com//how-to-know-when-your-postgres-service-is-ready/

I am sure a lot of us have found ourselves in a situation where we need to wait for a service to be ready. I don't mean the VM or container is running. I mean the service is up and running and fully functional.

Postgres provides an easy to use command called pg_isready that allows us to know exactly when postgres is ready to accept connections.

pg_isready is a utility for checking the connection status of a PostgreSQL database server. The exit status specifies the result of the connection check. (taken from https://www.postgresql.org/docs/9.6/static/app-pg-isready.html)

Example Script

Here is a simple shell script where we poll the postgres service every 2 seconds until it is ready to accept connections.

#!/bin/sh
pg_uri="postgres://postgres:postgres@postgrest-host:5432/shield"
# make sure pg is ready to accept connections
until pg_isready -h postgres-host -p 5432 -U postgres
do
  echo "Waiting for postgres at: $pg_uri"
  sleep 2;
done
# Now able to connect to postgres

The post How to know when your Postgres Service is ready appeared first on Stark & Wayne.

]]>

I am sure a lot of us have found ourselves in a situation where we need to wait for a service to be ready. I don't mean the VM or container is running. I mean the service is up and running and fully functional.

Postgres provides an easy to use command called pg_isready that allows us to know exactly when postgres is ready to accept connections.

pg_isready is a utility for checking the connection status of a PostgreSQL database server. The exit status specifies the result of the connection check. (taken from https://www.postgresql.org/docs/9.6/static/app-pg-isready.html)

Example Script

Here is a simple shell script where we poll the postgres service every 2 seconds until it is ready to accept connections.

#!/bin/sh
pg_uri="postgres://postgres:postgres@postgrest-host:5432/shield"
# make sure pg is ready to accept connections
until pg_isready -h postgres-host -p 5432 -U postgres
do
  echo "Waiting for postgres at: $pg_uri"
  sleep 2;
done
# Now able to connect to postgres

The post How to know when your Postgres Service is ready appeared first on Stark & Wayne.

]]>