scripts to kill running quries
PGDATEBASE=tntxprod
DATE=$(date +%G-%m-%d--%H-%M-%S-%N)
CHECK_LOG=/tmp/DBLOGS/$PGDATABASE_$DATE.log
/trandb/bin/psql -p 5444 -h localhost -c "select pg_terminate_backend(pid),a.* FROM pg_stat_activity a where state in ('active','idle in transaction') AND state_change < current_timestamp - INTERVAL '15' MINUTE and client_addr NOT IN ('10.236.70.242','10.236.243.135','10.236.243.136','192.168.50.65')" -U enterprisedb tntxprod >> "/tmp/DBLOGS/killconnectionapptimeoutsuccess$DATE.log" 2>> "/tmp/DBLOGS/killconnectionapptimeoutfailure$DATE.log"
echo "Starting Removing of Three Days Back Logs ######$DATE######" >>$CHECK_LOG
find /tmp/DBLOGS/kill* -mtime +3 -name 'kill*' -exec rm {} \; >>$CHECK_LOG
echo "End this Removing Logs Three Days Back completed#####$DATE ######" >>$CHECK_LOG
if [ $? -ne 0 ]
then
echo " Removing failed"
exit 1;
fi
echo "Removing Completed Successfuly" >> $CHECK_LOG
DATE=$(date +%G-%m-%d--%H-%M-%S-%N)
CHECK_LOG=/tmp/DBLOGS/$PGDATABASE_$DATE.log
/trandb/bin/psql -p 5444 -h localhost -c "select pg_terminate_backend(pid),a.* FROM pg_stat_activity a where state in ('active','idle in transaction') AND state_change < current_timestamp - INTERVAL '15' MINUTE and client_addr NOT IN ('10.236.70.242','10.236.243.135','10.236.243.136','192.168.50.65')" -U enterprisedb tntxprod >> "/tmp/DBLOGS/killconnectionapptimeoutsuccess$DATE.log" 2>> "/tmp/DBLOGS/killconnectionapptimeoutfailure$DATE.log"
echo "Starting Removing of Three Days Back Logs ######$DATE######" >>$CHECK_LOG
find /tmp/DBLOGS/kill* -mtime +3 -name 'kill*' -exec rm {} \; >>$CHECK_LOG
echo "End this Removing Logs Three Days Back completed#####$DATE ######" >>$CHECK_LOG
if [ $? -ne 0 ]
then
echo " Removing failed"
exit 1;
fi
echo "Removing Completed Successfuly" >> $CHECK_LOG
Comments
Post a Comment