rac中的job

本文详细介绍了Oracle RAC数据库中Job如何在不同级别上运行,包括实例级别和集群级别,以及如何在指定实例上创建Job并查看Job运行实例,同时说明了Job在实例间迁移的实现方式。

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

author:skate
time:2011/08/19

 

rac中的job

 

一个JOB在何级别运行是可以定制的。


对于集群数据库,如果把job定义在db级,job可以运行在任何活动的instance上,并遵循job的调度机制,
JOB的调度通过JOB协调进程来完成的,通过JQ队列锁来避免竞争和重复执行,每个JOB分配一个唯一的JQ锁;
如果把job定义在instance级别上,job将运行在指定的实例上,如因某种异常导致创建job的实例当机,那
job将运行在存活的实例上。

 

参考Oracle文档:
you can create a job at the cluster database level and the job will run on any active instance of the target Oracle RAC database. Or you can create a job at the instance level and the job will only run on the specific instance for which you created it. In the event of a failure, recurring jobs can run on a surviving instance.

Oracle文档说:
Each RAC instance has its own job coordinator. The database monitoring checks that determine whether or not to start the job coordinator do take the service affinity of jobs into account. For example, if there is only one job scheduled in the near future and the job class to which this job belongs has service affinity for only two out of the four RAC instances, only the job coordinators for those two instances will be started.

 

例子:


rac创建job(job默认是创建在‘0’实例上)

DECLARE
  X NUMBER;
BEGIN
  SYS.DBMS_JOB.SUBMIT
    (
      job        => X
     ,what       => 'declare
v_a nvarchar2(10);
begin
select '' a'' into v_a from dual;
end;'
     ,next_date  => to_date('08/19/2011 11:26:43','mm/dd/yyyy hh24:mi:ss')
     ,interval   => 'SYSDATE+30/1440 '
     ,no_parse   => FALSE
    );
:JobNumber := to_char(X);
END;


在指定实例上创建job

DECLARE
  X NUMBER;
BEGIN
  SYS.DBMS_JOB.SUBMIT
    (
      job        => X
     ,what       => 'declare
v_a nvarchar2(10);
begin
select '' a'' into v_a from dual;
end;'
     ,next_date  => to_date('08/19/2011 11:26:43','mm/dd/yyyy hh24:mi:ss')
     ,interval   => 'SYSDATE+30/1440 '
     ,no_parse   => FALSE
     ,instance  => 1
     ,force     => TRUE
    );
:JobNumber := to_char(X);
END;


现在查看下现有的job运行在哪个实例上

SQL> select job,instance,what from dba_jobs j where J.JOB in (41,42);

       JOB   INSTANCE WHAT
---------- ---------- --------------------------------------------------------------------------------
        41          0 declare
                      v_a nvarchar2(10);
                      begin
                      select ' a' into v_a from dual;
                      end;

        42          1 declare
                      v_a nvarchar2(10);
                      begin
                      select ' a' into v_a from dual;
                      end;


SQL>
SQL>

 

把job 41 更改到实例1上


SQL> exec dbms_job.instance(41,1);

PL/SQL procedure successfully completed

SQL> select job,instance,what from dba_jobs j where J.JOB in (41,42);

       JOB   INSTANCE WHAT
---------- ---------- --------------------------------------------------------------------------------
        41          1 declare
                      v_a nvarchar2(10);
                      begin
                      select ' a' into v_a from dual;
                      end;

        42          1 declare
                      v_a nvarchar2(10);
                      begin
                      select ' a' into v_a from dual;
                      end;


把job 42 更改到实例2上


SQL> exec dbms_job.instance(42,2);

PL/SQL procedure successfully completed

SQL> select job,instance,what from dba_jobs j where J.JOB in (41,42);

       JOB   INSTANCE WHAT
---------- ---------- --------------------------------------------------------------------------------
        41          1 declare
                      v_a nvarchar2(10);
                      begin
                      select ' a' into v_a from dual;
                      end;

        42          2 declare
                      v_a nvarchar2(10);
                      begin
                      select ' a' into v_a from dual;
                      end;


SQL>

 

 

 

--------------------end-----------------------

 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值