Search This Blog

Loading...

Sunday, November 7, 2010

Simple script to monitor replication in PostgreSQL 9

Here is the simple script to monitor PostgreSQL replication on FreeBSD:

========= Cut here =========
#!/bin/sh

# Timeout in seconds
readonly timeout=600

last_chkp=`pg_controldata /var/db/pgsql/ | grep "Time of latest checkpoint" | sed "s/.*checkpoint: *//"`
last_chkp=`date -j -f "%a %b %d %T %Z %Y" "$last_chkp" "+%s"`

now=`date`
now=`date -j -f "%a %b %d %T %Z %Y" "$now" "+%s"`

if [ `expr $now - $last_chkp` -gt $timeout ]; then
echo Replication kaput!
fi

2 comments:

Anonymous said...

Good article. Thank you.
http://www.erispan.350.com/

Order Levitra said...

You have a very good blog that the main thing a lot of interesting and useful!