• dbms_jobs vs. dbms_scheduler_jobs


    dba_jobs:This view lists all jobs inthe database.

    dba_scheduler_jobs:Job scheduler job detail.

    http://www.dba-oracle.com/t_dbms_job_scheduler.htm 

    I don't think you answered the question What's the difference between these two views?

    The answer is, There's no relationship.

    Traditional DBMS jobs (as we often call) are shown in dba_jobs.

    10g new type of scheduler jobs are shown in dba_scheduler_jobs.

      These are two types of jobs, and Oracle suggests we all use the new scheduler jobs

      because you can have more and better control and monitoring.

    If you schedule something to run using both dbms_jobs and dbms_scheduler_jobs packages,

    it will be run according to both schedulers and they're independent ofeach other.

    Of course it's silly to schedule the same thing twice.

     --sys用户执行以下sql语句,查看job的运行日志

    select t.owner,

           t.job_name,

           t.status,

           to_char(t.actual_start_date, 'yyyy-mm-dd hh24:mi:ss'),

           t.additional_info,

           t.error#

    from dba_scheduler_job_run_details t

    where t.owner = 'PSD

    order by log_date desc;

    SELECT job_name, job_name,

           avg(EXTRACT( DAY FROM run_duration )*24*60*60 + EXTRACT( HOUR FROM run_duration )*60*60 + EXTRACT( MINUTE FROM run_duration )*60 + EXTRACT( SECOND FROM run_duration ))

    FROM dba_scheduler_job_run_details

    GROUP BY job_name, job_name

    HAVING avg(EXTRACT( DAY FROM run_duration )*24*60*60 + EXTRACT( HOUR FROM run_duration )*60*60 + EXTRACT( MINUTE FROM run_duration )*60 + EXTRACT( SECOND FROM run_duration )) > 0

    ORDER BY 3 DESC;

    Starting with Oracle Database 10g, the Oracle scheduler was greatly improved with the dbms_scheduler package.  Replacing the dbms_job with dbms_scheduler offers additional features by adding the ability to tie jobs with specific user-type privileges and roles:

    Features Comparison between dbms_job and dbms_scheduler  

    Feature

    dbms_job

    dbms_scheduler

    Provide full integration of job creation and modification in Oracle Enterprise Manager.

    Yes

    Yes

    Provide privileges and roles specifically for the scheduler to increase control over the scheduling of jobs.

    No

    Yes

    Table 1.1 - Features comparison between the dbms_job and dbms_scheduler package

    See from Dr. Timothy Hall's book "Oracle Job Scheduling" these tips on migrating from dbms_job to dbms_scheduler:

    -- Old using dbms_job scheduler.

    VARIABLE l_job NUMBER; BEGIN   DBMS_JOB.submit (     job       => :l_job,     what      => 'BEGIN NULL; /* Do Nothing */ END;',     next_date => SYSDATE,     interval  => 'SYSDATE + 1 /* 1 Day */');       COMMIT; END; / PRINT l_job

    -- New with dbms_scheduler scheduler.

    BEGIN   DBMS_SCHEDULER.create_job (     job_name        => 'dummy_job',     job_type        => 'PLSQL_BLOCK',     job_action      => 'BEGIN NULL; /* Do Nothing */ END;',     start_date      => SYSTIMESTAMP,     repeat_interval => 'SYSTIMESTAMP + 1 /* 1 Day */'); END; /

    By comparing these examples, it is noted that conversion of basic jobs is quite simple, involving the following steps:

    • Define a meaningful job_name for the new job.  

    • Assign a job_action of PLSQL_BLOCK.  

    • Use the what value from the old job as the job_action value in the new job.  

    • Use SYSTIMESTAMP for the start_date value.  

    • Use the interval value from the old job as the repeat_interval value in the new job, making sure the result of the expression is a TIMESTAMP not a DATE.

    Once this conversion has been completed for all jobs, there is freedom from using the old scheduler, so the job_queue_processes parameter can now be set to zero.

              

    The new 10g job scheduling views

              

    Oracle MOSC also offers advice on moving from dbms_job to dbms_scheduler and notes that the dba_jobs view is obsolete with dbms_scheduler and we use dba_scheduler_jobs:

              

    select
       job_name,
       enabled
    from
       user_scheduler_jobs;

              

     
    and this:
     

              

    select    job_id,
       freq_type,
       freq_interval,
       freq_subday_type,
       freq_subday_interval,
       freq_relative_interval,
       freq_recurrence_factor,
       active_start_date,
       active_end_date,
       active_start_time, 
       active_end_time, 
       schedule_id
    from    dba_scheduler_jobs;

              

    MOSC also notes that internally-scheduled tasks (job queues, automatic statistics) can be seen by querying the dba_scheduler_jobs view:

    As the SYS user, use the following query to check for this job:
    SELECT STATE FROM DBA_SCHEDULER_JOBS WHERE JOB_NAME = 'GATHER_STATS_JOB';

    This DBASupport article shows the main DBA Scheduler views and a handy query:

      • DBA_SCHEDULER_SCHEDULES - provides me with information about the schedules that are in effect in the database.  

      • DBA_SCHEDULER_PROGRAMS - shows all program objects and their attributes, while view DBA_SCHEDULER_PROGRAM_ARGS shows all program arguments for programs that have them.  

      • DBA_SCHEDULER_JOBS - shows all job objects and their attributes.

    http://docs.oracle.com/cd/E11882_01/server.112/e25494/schedadmin.htm#ADMIN12035 Setting Oracle Scheduler Privileges

    You must have the SCHEDULER_ADMIN role to perform all Oracle Scheduler administration tasks. Typically, database administrators already have this role with the ADMIN option as part of the DBA role. For example, users SYS and SYSTEM are granted the DBA role. You can grant this role to another administrator by issuing the following statement: GRANT SCHEDULER_ADMIN TO username;

    Because the SCHEDULER_ADMIN role is a powerful role allowing a grantee to execute code as any user, you should consider granting individual Scheduler system privileges instead. Object and system privileges are granted using regular SQL grant syntax. An example is if the database administrator issues the following statement: GRANT CREATE JOB TO scott;

    After this statement is executed, scott can create jobs, schedules, programs, file watchers, and credentials in his schema. Another example is if the database administrator issues the following statement: GRANT MANAGE SCHEDULER TO adam;

    After this statement is executed, adam can create, alter, or drop windows, job classes, or window groups. He will also be able to set and retrieve Scheduler attributes and purge Scheduler logs.

    --dbms_job interval

    例如:

    declare

    JOB_ILEARN_ONLINE number :=1;

    begin

    dbms_job.submit(JOB_ILEARN_ONLINE,'insert into testdate(today) values(sysdate);',sysdate,'TRUNC(sysdate,''mi'') + 1 / (24*60) ');

    commit;

    end;

    1、每分钟执行

        Interval => TRUNC(sysdate, 'mi')+1/(24*60)

    2、每天定时执行

        例如:每天的凌晨2点执行

        Interval => TRUNC(sysdate)+1+2/(24)

    3、每周定时执行

        例如:每周一凌晨2点执行

        Interval => TRUNC(next_day(sysdate, 2))+2/24 --星期一,一周的第二天

    4、每月定时执行

        例如:每月1日凌晨2点执行

        Interval => TRUNC(LAST_DAY(SYSDATE))+1+2/24

    5、每季度定时执行

        例如每季度的第一天凌晨2点执行

        Interval => TRUNC(ADD_MONTH(SYSDATE), 3),'Q')+2/24

    6、每半年定时执行

        例如:每年7月1日和1月1日凌晨2点

        Interval => ADD_MONTHS(trunc(sysdate,'yyyy'),6)+2/24

    7、每年定时执行

        例如:每年1月1日凌晨2点执行

        Interval => ADD_MONTHS(trunc(sysdate,'yyyy'),12)+2/24

     

    All for u
  • 相关阅读:
    JQuery简介
    javascript中的正则表达式
    JSDom
    JavaScript事件的属性列表
    JavaScript中innerText和innerHTML的区别
    JavaScript设置粘贴板
    Windows.event
    Https:Java代码设置使用证书访问Https
    Https:证书生成 .p12 .keyStore 和 .truststore文件理解
    HTTP:HTTP请求头和响应头详解
  • 原文地址:https://www.cnblogs.com/ayumie/p/6406583.html
Copyright © 2020-2023  润新知