Postgresql introduced stream Replication in 9.0; Provides a high level of availability for DB clusters; This article provides an environmental monitoring script
Environment Construction: Reference--http://www.cnblogs.com/lottu/p/5584923.html
Environment switch: Reference--http://www.cnblogs.com/lottu/p/5725309.html
Provide the following script:
##=========================================================== ## postgres_db_check.sh## Created by Lottu## 2016/08/07## usage:postgres_db_check.sh##============================================================ #!/bin/bashExport LANG="En_us.utf8"Export DATE= ' Date +"%y%m%d"' Admail="[email protected]"Standby_number=1#there is only one repository for this environment;M_err_exit=20S_err_exit=21#determine if the main library is working correctly firstPg_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#View the status of stream replication in a cluster, which can be judged according to the table Pg_stat_replicationPsql-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 Environment Monitoring script