We have set up a series of uptime checks on all of our online services.
The last one is our Postgres DB. Given the connection URL in the format of:
postgres://username:password@domain-name:port/restriction
Does postgres comes out of the box with an http-callable url that would return a 200
if DB is up and 500
or nothing is DB is down?
Then, we can do a SQL query to get the uptime, like this: postgres=# SELECT current_timestamp - pg_postmaster_start_time(); ...
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.
You can use pg_isready to check the connection status of a PostgreSQL server
pg_isready --dbname=dbname --host=hostname --port=port --username=username
From the documentation:
pg_isready returns 0 to the shell if the server is accepting connections normally, 1 if the server is rejecting connections (for example during startup), 2 if there was no response to the connection attempt, and 3 if no attempt was made (for example due to invalid parameters).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With