Before running this script you can monitor Using "top -c" command and you can kill particular process using top command PID for example if unwanted backup is running mistaken schedule crontab then kill that job/process using this Linux shell script
As a dba I suggested don't use kill -9 instead of pg_cancel and pg_terminate command
cat kill.shecho " "echo " "HOSTNAME=`hostname`PSQL=" /opt/PostgreSQL/9.3/bin/psql"PORT=5432HOST="localhost"DB="template1"USER="postgres"echo "------***WHAT ARE THE QUERY IS RUNING MORE THAN 1 MINUTES***------"$PSQL -d $DB -U $USER -p $PORT < '1 minutes'::interval ORDER BY runtime DESC;EOFecho "Enter the value of PID which process you want to kill";read pid$PSQL -d $DB -U $USER -p $PORT <
Sample OutPut:
bash-4.1$ sh kill.sh------***WHAT ARE THE QUERY IS RUNING MORE THAN 1 MINUTES***------Output format is wrapped. pid | runtime | usename | datname | state | query-------+-----------------+-----------+----------+-------+------------ 30432 | 00:02:22.036876 | emutation | mhrordhu | idle | unlisten * 31761 | 00:02:21.739505 | emutation | mhrordhu | idle | unlisten * Enter the value of PID which process you want to kill30432 pg_terminate_backend---------------------- t(1 row)
0 comments:
Post a Comment