Shell 用于监视 postgresql 数据库状态和警报的脚本

Shell script to monitor postgresql database status and alerts

我需要 postgresql shell 脚本来在数据库出现故障时提醒我。

pg_isready 是一个用于检查 PostgreSQL 数据库服务器连接状态的实用程序。 exit 状态指定连接检查的结果。

示例:

while true; do
    if ! /usr/bin/pg_isready &>/dev/null; then 
        echo 'alert';
    fi;
    sleep 3;
done;

这将每 3 秒检查一次 postgresql 数据库的状态,如果它已关闭则回显 "alert"。

https://www.postgresql.org/docs/9.3/static/app-pg-isready.html