Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

URL to ping Postgres DB to check uptime

Tags:

postgresql

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?

like image 543
Augustin Riedinger Avatar asked Feb 10 '16 09:02

Augustin Riedinger


People also ask

How do I check PostgreSQL uptime?

Then, we can do a SQL query to get the uptime, like this: postgres=# SELECT current_timestamp - pg_postmaster_start_time(); ...

What is Pg_isready in PostgreSQL?

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.


1 Answers

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).

like image 128
Federico Avatar answered Oct 16 '22 22:10

Federico