標籤:
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=20s_err_exit=21#先判斷主庫是否正常運行pg_ctl status | grep runningif [ $? -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.outl=`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
PostgreSQL Hot Standby環境監測指令碼