大晚上抽出一点儿时间做个试验
比如出现了下面的错误,怎么解决呢
- SELECT JOB,WHAT,LOG_USER,TO_CHAR(LAST_DATE,'YYYY-MM-DD HH24:MI:SS'),TO_CHAR(NEXT_DATE,'YYYY-MM-DD HH24:MI:SS'),INTERVAL,FAILURES,broken from user_jobs;
- JOB WHAT LOG_USER TO_CHAR(LAST_DATE,' TO_CHAR(NEXT_DATE,' INTERVAL FAILURES B
- -- ----- --------------------------------------------------- ------------------ ---------- -
- 22 myproc; SCOTT 2011-10-27 21:59:44 2011-10-27 22:11:57 sysdate+1/2440 16 N
解决办法:
1、exec dbms_job.broken(22,false,sysdate+1/2440);
commit;
2、SQL> exec dbms_job.run(22,true);
commit;
如果不想让job立即执行,那么就用第二种。
下面是试验过程,很乱,实在没时间整理,凑合看吧
- 昨天,工作中一个oracle数据库中的两个job失败次数都达到16次了,job的broken状态都为y,也就是不再执行了。那么怎么解决呢?浸提晚上到家凑点儿时间做个小实验,来分析怎样让由于失败次数达到上限而不再自动执行的job恢复自动执行。
- 创建存储过程
- create or replace procedure myproc as
- begin
- insert into test values(sysdate);
- end;
- /
- 创建job,每半分钟执行一次
- variable n number;
- begin
- dbms_job.submit(:n,'myproc;',sysdate,'
- ');
- commit;
- end;
- /
- print :n
- job号为22
- 让job执行不成功
- alter table test rename to test2;
- 这样8分钟后,job错误执行次数达到16次,job的broken状态为Y,也就是这个job不再执行
- 查询状态
- SELECT JOB,WHAT,LOG_USER,TO_CHAR(LAST_DATE,'YYYY-MM-DD HH24:MI:SS'),TO_CHAR(NEXT_DATE,'YYYY-MM-DD HH24:MI:SS'),INTERVAL,FAILURES,broken from user_jobs;
- 那么怎么让他继续执行呢?
- 第一种方法:
- 先不将表名由test2改为test
- exec dbms_job.broken(22,false,sysdate+1/2440);
- commit;
- 这样再次查询
- SELECT JOB,WHAT,LOG_USER,TO_CHAR(LAST_DATE,'YYYY-MM-DD HH24:MI:SS'),TO_CHAR(NEXT_DATE,'YYYY-MM-DD HH24:MI:SS'),INTERVAL,FAILURES,broken from user_jobs;
- JOB WHAT LOG_USER TO_CHAR(LAST_DATE,' TO_CHAR(NEXT_DATE,' INTERVAL FAILURES B
- ---------- ------------ --------------- ------------------------------------------- -------------------- ---------- -
- 22 myproc; SCOTT 2011-10-27 21:59:44 2011-10-27 22:11:57 sysdate+1/2440 16 N
- 观察执行一次后的状态:22号job依然执行失败,failures失败次数变为17,broken变回Y,也就是以后不会再执行了。
- SQL> SELECT JOB,WHAT,LOG_USER,TO_CHAR(LAST_DATE,'YYYY-MM-DD HH24:MI:SS'),TO_CHAR(NEXT_DATE,'YYYY-MM-DD HH24:MI:SS'),INTERVAL,FAILURES,broken from user_jobs;
- JOB WHAT LOG_USER TO_CHAR(LAST_DATE,' TO_CHAR(NEXT_DATE,' INTERVAL FAILURES B
- ---------- ------------------------------ ------------------------------ ------------------- ------------------- ------------------------------ ---------- -
- 22 myproc; SCOTT 2011-10-27 21:59:44 4000-01-01 00:00:00 sysdate+1/2440 17 Y
- 将test2改为test
- SQL> alter table test2 rename to test;
- exec dbms_job.broken(22,false,sysdate+1/2440);
- commit;
- SQL> SELECT JOB,WHAT,LOG_USER,TO_CHAR(LAST_DATE,'YYYY-MM-DD HH24:MI:SS'),TO_CHAR(NEXT_DATE,'YYYY-MM-DD HH24:MI:SS'),INTERVAL,FAILURES,broken from user_jobs;
- JOB WHAT LOG_USER TO_CHAR(LAST_DATE,' TO_CHAR(NEXT_DATE,' INTERVAL FAILURES B
- ---------- ------------------------------ ------------------------------ ------------------- ------------------- ------------------------------ ---------- -
- 22 myproc; SCOTT 2011-10-27 21:59:44 4000-01-01 00:00:00 sysdate+1/2440 17 N
- 再观察,奇迹啊,这次执行成功了,失败次数归0,broken状态为n。
- SQL> SELECT JOB,WHAT,LOG_USER,TO_CHAR(LAST_DATE,'YYYY-MM-DD HH24:MI:SS'),TO_CHAR(NEXT_DATE,'YYYY-MM-DD HH24:MI:SS'),INTERVAL,FAILURES,broken from user_jobs;
- JOB WHAT LOG_USER TO_CHAR(LAST_DATE,' TO_CHAR(NEXT_DATE,' INTERVAL FAILURES B
- ---------- ------------------------------ ------------------------------ ------------------- ------------------- ------------------------------ ---------- -
- 22 myproc; SCOTT 2011-10-27 22:15:32 2011-10-27 22:16:07 sysdate+1/2440 0 N
- 第二种方法:
- alter table test rename to test2;
- 执行失败16次
- dbms_job.run(22,true);
- 执行失败
- ERROR at line 1:
- ORA-12011: execution of 1 jobs failed
- ORA-06512: at "SYS.DBMS_IJOB", line 406
- ORA-06512: at "SYS.DBMS_JOB", line 272
- ORA-06512: at line 1
- 为什么会这样,因为没有test这个表呗
- run成功后failures次数变为0,broken状态变为n。
- alter table test2 rename to test;
- dbms_job.run(22,true);
- 成功。
阅读(15399) | 评论(0) | 转发(0) |