oracle9i Job不能自动执行

近期公司对所有生产数据库开启日志审计,日志审计信息默认存在sys.aud$表中,为了防止sys.aud$表增长过快,写了一个自动清除脚本,该job每隔一个小时自动删除aud$表中的信息:

 

 

create or replace procedure clear_aud
as
begin
delete sys.aud$ where timestamp# <trunc(sysdate,'HH')- 1/24;
commit;
exception when others then 
rollback;
end;
/

Variable job number ;
begin
dbms_job.submit(:job, 'clear_aud;' ,trunc( sysdate + 1 / 24 , 'hh24' ), 'trunc(sysdate+1/24,''hh24'')' );
commit ;
end ;
/

 

 

 

在实施过程中,发现有个数据库的system表空间增长很快,查看aud$发现里面有几十万条记录,但是上面的自动清理脚本已经在该数据库上执行过了,故引起该问题的原因应该是该job没有自动执行,查看dba_jobs表,发现该job存在,但是不能自动执行:

 

 

SQL> select JOB,THIS_DATE,NEXT_DATE, TOTAL_TIME,WHAT, INSTANCE from dba_jobs;

       JOB THIS_DATE  NEXT_DATE  TOTAL_TIME WHAT                   INSTANCE
---------- ---------- ---------- ---------- -------------------- ----------
         1 2011-07-11                     0 clear_aud;                    0

 

 

表dba_jobs中的next_date字段表示job下次执行的时间, 该数据库中的next_date字段为空,说明该job不会自动执行,引用该问题的原因应该是spfile中的JOB_QUEUE_PROCESSES参数被设置为0了,官方文档对该参数的解释为:

 

You can schedule routines (jobs) to be run periodically using the job queue. To schedule a job you submit it to the job queue, using the Oracle suppliedDBMS_JOBpackage, and specify the frequency at which the job is to be run. Additional functionality enables you to alter, disable, or delete a job that you previously submitted.

Job queue (Jnnn)processes execute jobs in the job queue.For each instance, these job queue processes are dynamically spawned by a coordinator job queue (CJQ0) background process. The coordinator periodically selects jobs that are ready to run from the jobs shown in theDBA_JOBSview. It orders them by time, and then spawns Jnnnprocesses to run the selected jobs. Each Jnnnprocess executes one of the selected jobs.

TheJOB_QUEUE_PROCESSESinitialization parameter controls whether a coordinator job queue process is started by an instance. If this parameter is set to 0, no coordinator job queue process is started at database startup, and consequently no job queue jobs are executed. TheJOB_QUEUE_PROCESSESinitialization parameter also specifies the maximum number of Jnnnprocesses that can concurrently run on an instance. The maximum number of processes that can be specified is 1000.
 

该参数可以动态改变,故可执行更改命令,使该参数生效:

 

ALTER SYSTEM SET JOB_QUEUE_PROCESSES = 20;
 

你可能感兴趣的:(oracle)