I need postgresql shell script to alert me if database is goes down.
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.
Example:
while true; do
if ! /usr/bin/pg_isready &>/dev/null; then
echo 'alert';
fi;
sleep 3;
done;
This will check the status of postgresql database every 3 seconds and echos "alert" if it is down.
https://www.postgresql.org/docs/9.3/static/app-pg-isready.html
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