如果应用使用持久连接的话(例如连接池),这些进程的存活时间应该是比较长的。不过LOCAL=NO的进程有个现象就是,当客户端崩溃的时候(例如sql plus或toad无故死掉),oracle并不会自动释放他们之间建立的监听进程,这种情况长期累积之后也会对系统造成一定的资源浪费,所以应该经常检查一下是否有这样的进程存在并kill掉它们。
面脚本是kill 掉连接时间超过7天的网络连接的进程。 把脚本放在crontab里,定时执行即可。
1、Method A
ps -e -o pid -o etime -o args|grep LOCAL=NO|grep -v grep| \
awk '{ if (int(substr($2,1,index($2,"-")-1))>7) {print $1;} }'| \
xargs -t kill -9
2、Method B
ps -e -o pid -o etime -o args|grep LOCAL=NO|grep -v grep| \
awk '{ split($2,arr,"-"); if (arr[1]>7) {print $1;} }'| \
xargs -t kill -9
注:etime ELAPSED elapsed time since the process was started, in the form [[dd-]hh:]mm:ss.
3、Method C (not clever)
kill.sh:
ps -e -o pid -o etime -o args|grep LOCAL=NO>/tmp/tmpfile
cat /tmp/tmpfile|while read LINE
do
TIME=`echo $LINE|awk '{print $2}'`
TIME=`echo $TIME|awk -F: '{print $1}'`
if [ $TIME -gt 7]
then
echo $LINE >> /tmp/tmpflie2
fi
done
cut -c 1-5 /tmp/tmpfile2 |xargs -t -n1 kill -9
rm -f /tmp/tmpfile
rm -f /tmp/tmpfile2