管理的一套数据库的inactive的session 太多,每次手动删除太麻烦,写了一个shell自动删除
注:已在测试环境和生产环境中测试过,并没有实际使用。
#!/bin/bash
tmpfile0=/tmp/.kill_inactive_0
tmpfile1=/tmp/.kill_inactive_1
tmpfile2=/tmp/.kill_inactive_2
export ORACLE_SID=oramy01
sqlplus / as sysdba <
spool $tmpfile1
select 'kill time:'||to_char(sysdate,'yyyy-mm-dd hh24:mi:ss') execute_time from dual;
select p.spid,s.sid,s.serial# from v\$process p,v\$session s where s.paddr=p.addr and s.status='INACTIVE';
spool off
EOF
cat $tmpfile1>>$tmpfile0
grep "^[0123456789]" $tmpfile1 |awk '{print $2","$3}' > $tmpfile2
sed -i "/./{s/^/\'/g;s/$/\'/g}" $tmpfile2
for x in `cat $tmpfile2`
do
sqlplus / as sysdba <
alter system kill session $x immediate;
EOF
done
rm $tmpfile1 $tmpfile2
注:已在测试环境和生产环境中测试过,并没有实际使用。
#!/bin/bash
tmpfile0=/tmp/.kill_inactive_0
tmpfile1=/tmp/.kill_inactive_1
tmpfile2=/tmp/.kill_inactive_2
export ORACLE_SID=oramy01
sqlplus / as sysdba <
spool $tmpfile1
select 'kill time:'||to_char(sysdate,'yyyy-mm-dd hh24:mi:ss') execute_time from dual;
select p.spid,s.sid,s.serial# from v\$process p,v\$session s where s.paddr=p.addr and s.status='INACTIVE';
spool off
EOF
cat $tmpfile1>>$tmpfile0
grep "^[0123456789]" $tmpfile1 |awk '{print $2","$3}' > $tmpfile2
sed -i "/./{s/^/\'/g;s/$/\'/g}" $tmpfile2
for x in `cat $tmpfile2`
do
sqlplus / as sysdba <
alter system kill session $x immediate;
EOF
done
rm $tmpfile1 $tmpfile2
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/28881244/viewspace-1394106/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/28881244/viewspace-1394106/