关于oracle:设置定时清理Oracle长时间-INACTIVE-session-脚本

48次阅读

共计 1633 个字符,预计需要花费 5 分钟才能阅读完成。

设置定时清理 Oracle 长时间 INACTIVE session 脚本


复制间接执行,或者编辑到文件执行

#### 设置定时清理 Oracle 长时间 INACTIVE session 脚本
if [! -d "/home/oracle/cront/"];then
mkdir /home/oracle/cront
else
echo "Do nothing"
fi
# /home/oracle/cront/ks.sql
echo "set trimspool on
spool /home/oracle/cront/kills.sh replace
set pagesize 0
set heading off
set linesize 32767
SELECT 'kill -9' || P.SPID FROM V\$PROCESS P WHERE P.ADDR IN (SELECT B.PADDR FROM V\$SESSION B WHERE B.TYPE = 'USER' AND B.STATUS = 'INACTIVE' AND B.LAST_CALL_ET > 3600);
exit;
spool off" > /home/oracle/cront/ks.sql
# /home/oracle/cront/debug.sql
echo "oradebug wakeup 2;
exit;" > /home/oracle/cront/debug.sql
# /home/oracle/cront/ks.sh
echo '#!/bin/bash' > /home/oracle/cront/ks.sh
echo "source /home/oracle/.bash_profile
sqlplus / as sysdba @/home/oracle/cront/ks.sql
grep \"kill\" /home/oracle/cront/kills.sh > /home/oracle/cront/kill.sh
echo -e >> /home/oracle/cront/cron_kill.log
echo \"################# Started'kill -9'commend at \`date +'%F %T %A'\` ##################\" > /home/oracle/cront/cron_kill.log
echo -e >> /home/oracle/cront/cron_kill.log
# Kill session
/home/oracle/cront/kill.sh >> /home/oracle/cront/cron_kill.log
# oradebug
echo \"# oradebug , No Information Return\" >> /home/oracle/cront/cron_kill.log
sqlplus / as sysdba @/home/oracle/cront/debug.sql
# Info
echo -e >> /home/oracle/cront/cron_kill.log
echo \"Warning: \`cat /home/oracle/cront/kill.sh | wc -l\` processes Killed. \" >> /home/oracle/cront/cron_kill.log
echo -e >> /home/oracle/cront/cron_kill.log 
echo \"################  Stoped at \`date +'%F %T'\` ################\" >> /home/oracle/cront/cron_kill.log
" >> /home/oracle/cront/ks.sh
# Grant execute permission
chmod +x /home/oracle/cront/*
# Add Crontd
(crontab -l | grep -v "ks.sh") | crontab
(crontab -l ; echo "*/30 * * * * /bin/bash /home/oracle/cront/ks.sh") | crontab

正文完
 0