Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Shell script to monitor postgresql database status and alerts

I need postgresql shell script to alert me if database is goes down.

like image 863
pramod Avatar asked Nov 29 '25 01:11

pramod


1 Answers

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

like image 108
alibaba Avatar answered Dec 01 '25 23:12

alibaba