#!/bin/bash
threshold=50;
dt=`date +%Y%m%d%H%M%S`;
active=`/usr/bin/psql www -Atc "select count(*) from pg_stat_activity where current_query not ilike '%idle%';"`
if [[ active -gt threshold ]]; then
	echo "there are "$active" backends";
	echo "creating backup for pg_stat as pg_stat_bk_$dt"
	psql www -c "select * into monitoring.pg_stat_bk_$dt from pg_stat_activity where current_query not ilike '%idle%';"
fi

