定时kill长事务脚本kill_long_session.sh

为确保Oracle数据库中OGG抽取进程的稳定运行,通过定时任务自动查找并终止长时间运行的事务,避免归档日志被删除导致抽取进程异常停止。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

定时kill长事务


因为ogg抽取进程需要一定的归档,防止归档被删除,所以定时kill长事务,防止抽取进程abend


--kill_long_session.sh
#!/bin/sh
tmpfile0=/oracle/temp/monitor/kill_0.log
tmpfile1=/oracle/temp/monitor/kill_1.log
tmpfile2=/oracle/temp/monitor/kill_2.log
sqlplus / as sysdba < spool $tmpfile1
set feedback off
select 'kill time:'||to_char(sysdate,'yyyy-mm-dd hh24:mi:ss') execute_time from dual;
set line 200
set pages 1000
col username for a15
col command for a70
col machine for a20
col terminal for a20
col program for a20
select /*+rule*/ p.spid,s.sid,s.serial#,s.sql_id,s.username,s.machine,s.terminal,s.program
from v\$process p,v\$session s 
where s.paddr=p.addr and s.username<>'SYS' and s.type='USER'
and s.saddr in (select t.ses_addr from v\$transaction t where to_date(t.start_time, 'mm/dd/yy hh24:mi:ss') < sysdate - 5/24);
spool off
EOF
cat $tmpfile1>>$tmpfile0
grep "^[0123456789]" $tmpfile1 |awk '{print $1}'>$tmpfile2
for x in `cat $tmpfile2`
do
kill -9 $x
done
rm $tmpfile1 $tmpfile2



--contab 调度
00 * * * * /oracle/temp/monitor/kill_long_session.sh>>/oracle/temp/monitor/kill_long_session.log

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/24996904/viewspace-1178047/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/24996904/viewspace-1178047/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值