【问题标题】:Shell script to monitor postgresql database status and alerts用于监控 postgresql 数据库状态和警报的 Shell 脚本
【发布时间】:2017-06-13 09:08:07
【问题描述】:

如果数据库出现故障,我需要 postgresql shell 脚本来提醒我。

【问题讨论】:

  • while true; do psql -c "select 1"; if [ $? -gt 0 ]; then echo 'alert'; fi; sleep 1; done;
  • 你能告诉我这个shell脚本的逻辑吗?
  • 它尝试每秒连接一次数据库,如果失败,则回显“警报”

标签: postgresql postgresql-9.4


【解决方案1】:

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

例子:

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

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-11-04
    • 2019-07-30
    • 1970-01-01
    • 2017-02-19
    • 2020-06-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多