Postgresql 在9.0引进了Stream Replication;为数据库集群提供一种高可用性;本文提供一个环境监测脚本
环境搭建: 参考--http://www.cnblogs.com/lottu/p/5584923.html
环境切换: 参考--http://www.cnblogs.com/lottu/p/5725309.html
提供脚本如下:
##=========================================================== ## postgres_db_check.sh ## created by lottu ## 2016/08/07 ## usage: postgres_db_check.sh ##============================================================ #!/bin/bash export LANG="en_US.utf8" export DATE=`date +"%Y%m%d"` admail="[email protected]" standby_number=1 #本环境只有一个备库; m_err_exit=20 s_err_exit=21 #先判断主库是否正常运行 pg_ctl status | grep running if [ $? -ne 0 ];then echo "master postgres db is not running;please check it!" | mail -s "master postgres db is not running" $admail exit ${m_err_exit} fi #查看集群中流复制的状态;可根据表pg_stat_replication进行判断 psql -t -q -c "select client_addr,sync_state,state from pg_stat_replication" > lottu.out l=`awk -F"|" ‘/streaming/{n+=1}END{print n}‘ lottu.out` if [ $l -ne ${standby_number} ];then echo "standby postgres db is not running;please check it!" | mail -s "standby postgres db is not running" $admail exit ${s_err_exit} fi
时间: 2024-10-11 12:36:26