Postgressql (re)starting & monitoring with Monit

1) Install monit

apt-get install monit -y

2) Config Monit for postgresql

Create a monit config file for the postgresql init.d service

nano /etc/monit/conf.d/postgrsql.monit.conf

Append the following

check process postgres with pidfile /var/run/postgresql/9.2-main.pid
    start program = "/etc/init.d/postgresql start"
    stop program = "/etc/init.d/postgresql stop"

3) Check monit config syntax

monit -t

4) Restart monit to effect changes

service monit restart

5) Check monit

monit status

6) View Monit log files

tail -n 50 /var/log/monit.log