Skip to Main Content
  • Questions
  • Suspending and de-sudpending DBMS_JOB jobs

Breadcrumb

Question and Answer

Tom Kyte

Thanks for the question, David.

Asked: February 16, 2001 - 8:13 am UTC

Last updated: April 14, 2005 - 2:56 pm UTC

Version: 7.3.4.5 and 8.1.6.0.0 and hopefully generic

Viewed 1000+ times

You Asked

Hi Tom,

We have the requirement to automate the function of teporarily suspending all DBMS_JOB jobs, waiting until currently running jobs are finished, before firing certain processes, and then de-suspending all DBMS_JOBS after the process in question. So my question, bearing in mind that if a job is marked as broken whilst currently running then all details, including broken status, are reset on successful completion, what is the optimum way to suspend all DBMS_JOB jobs, check and wait for currently running jobs to finish, and, seperately de-suspend all DBMS_JOB jobs.

TIA
Regards
David

and Tom said...

Well, in 8.0 and up, the easiest approach is:

ALTER SYSTEM SET JOB_QUEUE_PROCESSES=0;


that'll shutdown the job queues after they finish their jobs. Unfortunately, that'll not work in 7.3 as that parameter could not be changed online.

In 7.3, I cannot think of a way to do this at the database level. All of the parameters for the jobs are reset pretty much at the end of the job -- so if you tried to set the NEXT_DATE way out in the future, at the end of the job, it'll just set it back on you (like broken is). Changing the interval of a running job won't help as the interval is used immediately BEFORE the job is started.

I guess you would have to (in 7.3) set the broken flag on all jobs that are not running and then monitor dba_jobs_running. As jobs complete, set their broken flag as well. Running a query such as:

1 select job, cnt
2 from user_jobs,
3 ( select count(*) cnt
4 from dba_jobs_running )
5 where broken = 'N'
6 and job not in ( select job from dba_jobs_running )
7 union all
8 select -1, count(*) cnt
9* from dba_jobs_running


and while CNT > 0, setting the broken flag for any positive job that is returned.




Rating

  (2 ratings)

Is this answer out of date? If it is, please let us know via a Comment

Comments

DBMS JOB FAILED AND WHILE SHUTTING DOWN ORA_J000_SID HANGING

SREENIVASA RAO, November 03, 2004 - 2:57 am UTC

Hi tom,
sorry tom,once again i come to you on other thread.
MY production DB running on 9.2.0.1.0, one day when 30 users were connected ,i started gather schema stats.

So the alert logfile has shown message like
---------------alert log file--------------------------
Fri Oct 29 20:16:02 2004
ORA-01555 caused by SQL statement below (Query Duration=4938 sec, SCN: 0x0000.0d2ef122):
Fri Oct 29 20:16:02 2004
SELECT COMPANYID, comp_appl_id from lot_workflowstage_dtl where
stage = 'DDUPEXEC' and stagestatus = 'P'
order by comp_appl_id
Fri Oct 29 20:16:02 2004
Errors in file /oracledb/oracledata/admin/RFES/bdump/rfes_j000_4510.trc:
ORA-12012: error on auto execute of job 7
ORA-01555: snapshot too old: rollback segment number 2 with name "_SYSSMU2$" too small
ORA-06512: at "SCB.PROC_RUN_DEDUP_BATCH", line 12
ORA-06512: at line 3
Fri Oct 29 20:26:43 2004
------------------------------------------------------
then i cut down gather schema stats.
job 7 has following procedure.........
************TEXT
--------------------------------------------------------------------------------
in_comp_appl_id number(8) ;
begin
for x in cur_rec loop
PROC_DEDUP_MATCH(x.COMPANYID, x.comp_appl_id, null, null, null, out_val);
out_val := pkgworkflow.updateworkflow(x.COMPANYID, x.comp_appl_id, null, '
DDUPEXEC', null, null, 'SYSTEMI', 'C', dummyval1, dummyval2, dummyval3);

if out_val is not null then
rollback;
insert_error(x.comp_appl_id,'Workflow Error Occured : ' || out_val, null
,'Job Scheduler for Dedup Process');

TEXT
--------------------------------------------------------------------------------

delete from lot_workflowstage_dtl
where stage in ('DDUPEXEC') and stagestatus = 'P'
and (comp_appl_id,stage) in
(select comp_appl_id,stage from lot_workflowstage_dtl where
stage = 'DDUPEXEC' and comp_appl_id = x.comp_appl_id
group by comp_appl_id,stage
having count(*) > 1 );

delete from lot_workflowstage_dtl
where stage in ('STYMFILE') and stagestatus = 'P'

TEXT
--------------------------------------------------------------------------------
and (comp_appl_id,stage) in (select comp_appl_id,stage from lot_wo
rkflowstage_dtl where

stage = 'STYMFILE' and comp_appl_id = x.comp_appl_id
group by comp_appl_id,stage
having count(*) > 1 );

commit;
else
commit;
end if;

TEXT************************


Then i tried to shutdown the database then ora_j000_rfes is hanging.SO i killed that background process .then db shutdown immediately.
Afer startup also the count on lot_workflowstage_dtl running very slow .it is showing uncompleted jobs lot.

then i rebuilt the indexes and shutdown db (by killing the ora_j000_sid) as well as manully kept job 7 in broken status and rerun .
SO that its running fine now.

could you guess the problem which was raised and pls give me the solution to avoid in future.
thanks in advance.

Tom Kyte
November 03, 2004 - 7:06 am UTC

shutdown immediate or shutdown abort would have shutdown.

there is no "problem" here -- you have a job, that job is trying really hard to run. shutdown waits patiently for things to finish. (immediate/abort would shutdown). When you restart -- the job tries hard to finish again.

You have simply said "don't care about job, don't run it". if you are happy with that -- great, else you are going to have to run the job sometime.

Suspend dbms_job even the one thats running

sonali, April 14, 2005 - 2:51 pm UTC

We want to be able to suspend all the jobs that are running for a perticular schema during upgrade of application and de-suspend all after the upgrade is done. We are using oracle 8.1.7.4, 9i and 10g.

I wanted to keep it simple so I used what you have suggested
ALTER SYSTEM SET JOB_QUEUE_PROCESSES=0; to suspend all the queued jobs, but the job which was in already running did not get suspended. Any easy way to do that ?

Thanks

Tom Kyte
April 14, 2005 - 2:56 pm UTC

kill it, alter system kill session, kill the job queue. after setting to zero

More to Explore

DBMS_JOB

More on PL/SQL routine DBMS_JOB here