The easiest way how to monitor if PostgreSQL is up and running without causing any necessary load on database is to connect and get just pid of the session using command select pg_backend_pid(); – this is very lightweight action.

I set this monitoring using telegraf:

sqlquery=”select pg_backend_pid();”

Since telegraf keeps session open you will get still the same PID. If database is restarted PID changes – so you can easily monitor changes of this value or missing values.