我需要postgresql shell脚本来提醒我数据库是否发生故障。
答案 0 :(得分:3)
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