scheduler in oracle database 10g-凯发app官方网站

凯发app官方网站-凯发k8官网下载客户端中心 | | 凯发app官方网站-凯发k8官网下载客户端中心
  • 博客访问: 3977568
  • 博文数量: 536
  • 博客积分: 10470
  • 博客等级: 上将
  • 技术积分: 4825
  • 用 户 组: 普通用户
  • 注册时间: 2006-05-26 14:08
文章分类

全部博文(536)

文章存档

2024年(3)

2021年(1)

2019年(1)

2017年(1)

2016年(2)

2013年(2)

2012年(10)

2011年(43)

2010年(10)

2009年(17)

2008年(121)

2007年(252)

2006年(73)

相关博文
  • ·
  • ·
  • ·
  • ·
  • ·
  • ·
  • ·
  • ·
  • ·
  • ·

分类: oracle

2007-03-20 17:06:14

oracle 10g includes a comprehensive scheduler (dbms_scheduler) to replace and extend the functionality provided by the dbms_job package. jobs form the core of the functionality, but there are several other components available:

    programs

    the scheduler allows you to optionally create programs which hold metadata about a task, but no schedule information. a program may related to a pl/sql block, a stored procedure or an os executable file. programs are created using the create_program procedure:
    -- create the test programs.
    begin
    -- pl/sql block.
    dbms_scheduler.create_program (
    program_name => 'test_plsql_block_prog',
    program_type => 'plsql_block',
    program_action => 'begin dbms_stats.gather_schema_stats(''scott''); end;',
    enabled => true,
    comments => 'program to gather scott''s statistics using a pl/sql block.');

    -- shell script.
    dbms_scheduler.create_program (
    program_name => 'test_executable_prog',
    program_type => 'executable',
    program_action => '/u01/app/oracle/dba/gather_scott_stats.sh',
    number_of_arguments => 0,
    enabled => true,
    comments => 'program to gather scott''s statistics us a shell script.');

    -- stored procedure with arguments.
    dbms_scheduler.create_program (
    program_name => 'test_stored_procedure_prog',
    program_type => 'stored_procedure',
    program_action => 'dbms_stats.gather_schema_stats',
    number_of_arguments => 1,
    enabled => false,
    comments => 'program to gather scott''s statistics using a stored procedure.');

    dbms_scheduler.define_program_argument (
    program_name => 'test_stored_procedure_prog',
    argument_name => 'ownname',
    argument_position => 1,
    argument_type => 'varchar2',
    default_value => 'scott');

    dbms_scheduler.enable (name => 'test_stored_procedure_prog');
    end;
    /

    pl/sql procedure successfully completed.

    -- display the program details.
    select owner, program_name, enabled from dba_scheduler_programs;

    owner program_name enabl
    ------------------------------ ------------------------------ -----
    sys purge_log_prog true
    sys gather_stats_prog true
    sys test_plsql_block_prog true
    sys test_executable_prog true
    sys test_stored_procedure_prog true

    5 rows selected.
    notice how programs that accept arguments must have the arguments defined before they can be enabled.

    programs can be deleted using the drop_program procedure:
    begin
    dbms_scheduler.drop_program (program_name => 'test_plsql_block_prog');
    dbms_scheduler.drop_program (program_name => 'test_stored_procedure_prog');
    dbms_scheduler.drop_program (program_name => 'test_executable_prog');
    end;
    /

    pl/sql procedure successfully completed.

    -- display the program details.
    select owner, program_name, enabled from dba_scheduler_programs;

    owner program_name enabl
    ------------------------------ ------------------------------ -----
    sys purge_log_prog true
    sys gather_stats_prog true

    2 rows selected.

    schedules

    schedules optionally define the start time, end time and interval related to a job. schedules are created using the create_schedule procedure:
    -- create the schedule.
    begin
    dbms_scheduler.create_schedule (
    schedule_name => 'test_hourly_schedule',
    start_date => systimestamp,
    repeat_interval => 'freq=hourly; byminute=0',
    end_date => null,
    comments => 'repeats hourly, on the hour, for ever.');
    end;
    /

    pl/sql procedure successfully completed.

    -- display the schedule details.
    select owner, schedule_name from dba_scheduler_schedules;

    owner schedule_name
    ------------------------------ ------------------------------
    sys daily_purge_schedule
    sys test_hourly_schedule

    2 rows selected.
    notice how the interval is defined using the calendaring syntax. a schedule can be dropped using the drop_schedule procedure:
    begin
    dbms_scheduler.drop_schedule (schedule_name => 'test_hourly_schedule');
    end;
    /

    pl/sql procedure successfully completed.

    -- display the schedule details.
    select owner, schedule_name from dba_scheduler_schedules;

    owner schedule_name
    ------------------------------ ------------------------------
    sys daily_purge_schedule

    1 row selected.

    jobs

    jobs are what the scheduler is all about. they can either be made up of predefined parts (programs and schedules) or completely self contained depending on which overload of the create_job procedure is used to create them:
    -- create jobs.
    begin
    -- job defined entirely by the create job procedure.
    dbms_scheduler.create_job (
    job_name => 'test_full_job_definition',
    job_type => 'plsql_block',
    job_action => 'begin dbms_stats.gather_schema_stats(''scott''); end;',
    start_date => systimestamp,
    repeat_interval => 'freq=hourly; byminute=0',
    end_date => null,
    enabled => true,
    comments => 'job defined entirely by the create job procedure.');

    -- job defined by an existing program and schedule.
    dbms_scheduler.create_job (
    job_name => 'test_prog_sched_job_definition',
    program_name => 'test_plsql_block_prog',
    schedule_name => 'test_hourly_schedule',
    enabled => true,
    comments => 'job defined by an existing program and schedule.');

    -- job defined by existing program and inline schedule.
    dbms_scheduler.create_job (
    job_name => 'test_prog_job_definition',
    program_name => 'test_plsql_block_prog',
    start_date => systimestamp,
    repeat_interval => 'freq=hourly; byminute=0',
    end_date => null,
    enabled => true,
    comments => 'job defined by existing program and inline schedule.');

    -- job defined by existing schedule and inline program.
    dbms_scheduler.create_job (
    job_name => 'test_sched_job_definition',
    schedule_name => 'test_hourly_schedule',
    job_type => 'plsql_block',
    job_action => 'begin dbms_stats.gather_schema_stats(''scott''); end;',
    enabled => true,
    comments => 'job defined by existing schedule and inline program.');
    end;
    /

    pl/sql procedure successfully completed.

    -- display job details.
    select owner, job_name, enabled from dba_scheduler_jobs;

    owner job_name enabl
    ------------------------------ ------------------------------ -----
    sys purge_log true
    sys gather_stats_job true
    sys test_full_job_definition true
    sys test_prog_sched_job_definition true
    sys test_prog_job_definition true
    sys test_sched_job_definition true

    6 rows selected.
    jobs are normally run asynchronously under the control of the job coordinator, but they can be controlled manually using the run_job and stop_job procedures:
    begin
    -- run job synchronously.
    dbms_scheduler.run_job (job_name => 'test_full_job_definition',
    use_current_session => false);

    -- stop jobs.
    dbms_scheduler.stop_job (job_name => 'test_full_job_definition, test_prog_sched_job_definition');
    end;
    /
    jobs can be deleted using the drop_job procedure:
    begin
    dbms_scheduler.drop_job (job_name => 'test_full_job_definition');
    dbms_scheduler.drop_job (job_name => 'test_prog_sched_job_definition');
    dbms_scheduler.drop_job (job_name => 'test_prog_job_definition');
    dbms_scheduler.drop_job (job_name => 'test_sched_job_definition');
    end;
    /

    pl/sql procedure successfully completed.

    -- display job details.
    select owner, job_name, enabled from dba_scheduler_jobs;

    owner job_name enabl
    ------------------------------ ------------------------------ -----
    sys purge_log true
    sys gather_stats_job true

    2 rows selected.

    job classes

    job classes allow grouping of jobs with similar characteristics and resource requierments which eases administration. if the job_class parameter of the create_job procedure is undefined the job is assigned to the default_job_class. a job class is created using the create_job_class procedure:
    -- display the current resource consumer groups.
    select consumer_group from dba_rsrc_consumer_groups;

    consumer_group
    ------------------------------
    other_groups
    default_consumer_group
    sys_group
    low_group
    auto_task_consumer_group

    5 rows selected.

    -- create a job class.
    begin
    dbms_scheduler.create_job_class (
    job_class_name => 'test_job_class',
    resource_consumer_group => 'low_group');
    end;
    /

    pl/sql procedure successfully completed.

    -- display job class details.
    select job_class_name, resource_consumer_group from dba_scheduler_job_classes;

    job_class_name resource_consumer_group
    ------------------------------ ------------------------------
    default_job_class
    auto_tasks_job_class auto_task_consumer_group
    test_job_class low_group

    3 rows selected.
    jobs can be assigned to a job class either during or after creation using the set_attribute procedure:
    begin
    -- job defined by an existing program and schedule and assigned toa job class.
    dbms_scheduler.create_job (
    job_name => 'test_prog_sched_class_job_def',
    program_name => 'test_plsql_block_prog',
    schedule_name => 'test_hourly_schedule',
    job_class => 'test_job_class',
    enabled => true,
    comments => 'job defined by an existing program and schedule and assigned toa job class.');

    dbms_scheduler.set_attribute (
    name => 'test_prog_sched_job_definition',
    attribute => 'job_class',
    value => 'test_job_class');
    end;
    /

    pl/sql procedure successfully completed.

    -- display job details.
    select owner, job_name, job_class, enabled from dba_scheduler_jobs;

    owner job_name job_class enabl
    ------------------------------ ------------------------------ ------------------------------ -----
    sys purge_log default_job_class true
    sys gather_stats_job auto_tasks_job_class true
    sys test_full_job_definition default_job_class true
    sys test_prog_sched_job_definition test_job_class true
    sys test_prog_job_definition default_job_class true
    sys test_sched_job_definition default_job_class true
    sys test_prog_sched_class_job_def test_job_class true

    7 rows selected.
    job classes can be dropped using drop_job_class procedure:
    begin
    dbms_scheduler.drop_job_class (
    job_class_name => 'test_job_class',
    force => true);
    end;
    /

    pl/sql procedure successfully completed.

    -- display job class details.
    select job_class_name, resource_consumer_group from dba_scheduler_job_classes;

    job_class_name resource_consumer_group
    ------------------------------ ------------------------------
    default_job_class
    auto_tasks_job_class auto_task_consumer_group

    2 rows selected.
    the force option disables any dependent jobs and sets their job class to the default value. if the job class has no dependents the force option is not necessary.

    windows

    windows provide the link between the scheduler and the resource manager, allowing different resource plans to be activated at different times. since job classes point to resource consumer groups, and therefore resource plans, this mechanism allows control over the resources allocated to job classes and their jobs during specific time periods.

    only one window can be active (open) at any time, with one resource plan assigned to the window. the affect of resource plan switches is instantly visible to running jobs which are assigned to job classes. the interaction between the resource manager and the scheduler is beyond the scope of this document.

    a window can be created using the create_window procedure with a predefined or an inline schedule:
    begin
    -- window with a predefined schedule.
    dbms_scheduler.create_window (
    window_name => 'test_window_1',
    resource_plan => null,
    schedule_name => 'test_hourly_schedule',
    duration => interval '60' minute,
    window_priority => 'low',
    comments => 'window with a predefined schedule.');

    -- window with an inline schedule.
    dbms_scheduler.create_window (
    window_name => 'test_window_2',
    resource_plan => null,
    start_date => systimestamp,
    repeat_interval => 'freq=hourly; byminute=0',
    end_date => null,
    duration => interval '60' minute,
    window_priority => 'low',
    comments => 'window with an inline schedule.');
    end;
    /

    pl/sql procedure successfully completed.

    -- display window group details.
    select window_name, resource_plan, enabled, active
    from dba_scheduler_windows;

    window_name resource_plan enabl activ
    ------------------------------ ------------------------------ ----- -----
    weeknight_window true false
    weekend_window true false
    test_window_1 true false
    test_window_2 true false

    4 rows selected.
    windows can be opened and closed manually using the open_window and close_window procedures:
    begin
    -- open window.
    dbms_scheduler.open_window (
    window_name => 'test_window_2',
    duration => interval '1' minute,
    force => true);
    end;
    /

    pl/sql procedure successfully completed.

    -- display window group details.
    select window_name, resource_plan, enabled, active
    from dba_scheduler_windows;

    window_name resource_plan enabl activ
    ------------------------------ ------------------------------ ----- -----
    weeknight_window true false
    weekend_window true false
    test_window_1 true false
    test_window_2 true true

    4 rows selected.

    begin
    -- close window.
    dbms_scheduler.close_window (
    window_name => 'test_window_2');
    end;
    /

    pl/sql procedure successfully completed.

    -- display window group details.
    select window_name, resource_plan, enabled, active
    from dba_scheduler_windows;

    window_name resource_plan enabl activ
    ------------------------------ ------------------------------ ----- -----
    weeknight_window true false
    weekend_window true false
    test_window_1 true false
    test_window_2 true false

    4 rows selected.
    windows can be dropped using the drop_window procedure:
    begin
    dbms_scheduler.drop_window (
    window_name => 'test_window_1',
    force => true);

    dbms_scheduler.drop_window (
    window_name => 'test_window_2',
    force => true);
    end;
    /

    pl/sql procedure successfully completed.

    -- display window group details.
    select window_name, resource_plan, enabled, active
    from dba_scheduler_windows;

    window_name resource_plan enabl activ
    ------------------------------ ------------------------------ ----- -----
    weeknight_window true false
    weekend_window true false

    2 rows selected.

    windows groups

    a window group is a collection of related windows. it can be created with 0, 1 or many windows as group members using the create_window_group procedure:
    begin
    dbms_scheduler.create_window_group (
    group_name => 'test_window_group',
    window_list => 'test_window_1, test_window_2',
    comments => 'a test window group');
    end;
    /

    pl/sql procedure successfully completed.

    -- display window group details.
    select window_group_name, enabled, number_of_windows
    from dba_scheduler_window_groups;

    window_group_name enabl number_of_windows
    ------------------------------ ----- -----------------
    maintenance_window_group true 2
    test_window_group true 2

    2 rows selected.
    windows can be added and removed from a group using the add_window_group_member and remove_window_group_member procedures:
    begin
    -- create a new window.
    dbms_scheduler.create_window (
    window_name => 'test_window_3',
    resource_plan => null,
    schedule_name => 'test_hourly_schedule',
    duration => interval '60' minute,
    window_priority => 'low',
    comments => 'window with a predefined schedule.');

    dbms_scheduler.add_window_group_member (
    group_name => 'test_window_group',
    window_list => 'test_window_3');
    end;
    /

    pl/sql procedure successfully completed.

    -- display window group members.
    select window_group_name, window_name
    from dba_scheduler_wingroup_members;

    window_group_name window_name
    ------------------------------ ------------------------------
    maintenance_window_group weeknight_window
    maintenance_window_group weekend_window
    test_window_group test_window_1
    test_window_group test_window_2
    test_window_group test_window_3

    5 rows selected.

    begin
    dbms_scheduler.remove_window_group_member (
    group_name => 'test_window_group',
    window_list => 'test_window_3');
    end;
    /

    pl/sql procedure successfully completed.

    -- display window group members.
    select window_group_name, window_name
    from dba_scheduler_wingroup_members;

    window_group_name window_name
    ------------------------------ ------------------------------
    maintenance_window_group weeknight_window
    maintenance_window_group weekend_window
    test_window_group test_window_1
    test_window_group test_window_2

    4 rows selected.
    window groups can be dropped using the drop_window_group procedure:
    begin
    dbms_scheduler.drop_window_group (
    group_name => 'test_window_group',
    force => true);
    end;
    /

    pl/sql procedure successfully completed.

    -- display window group details.
    select window_group_name, enabled, number_of_windows
    from dba_scheduler_window_groups;

    window_group_name enabl number_of_windows
    ------------------------------ ----- -----------------
    maintenance_window_group true 2

    1 row selected.
    the force option must be used if the window group currently has members.

    enable, disable and attributes

    all applicable scheduler objects can be enabled and disabled using the overloaded enable and disable procedures:
    begin
    -- enable programs and jobs.
    dbms_scheduler.enable (name => 'test_stored_procedure_prog');
    dbms_scheduler.enable (name => 'test_full_job_definition');

    -- disable programs and jobs.
    dbms_scheduler.disable (name => 'test_stored_procedure_prog');
    dbms_scheduler.disable (name => 'test_full_job_definition');
    end;
    /
    the values for individual attributes of all scheduler objects can be altered using one of the set_attribute overloads:
    begin
    dbms_scheduler.set_attribute (
    name => 'hourly_schedule',
    attribute => 'repeat_interval',
    value => 'freq=hourly; byminute=30');
    end;
    /
    the values can be set to null using the set_attribute_null procedure:
    begin
    dbms_scheduler.set_attribute_null (
    name => 'hourly_schedule',
    attribute => 'repeat_interval');
    end;
    /
    for more information see:
      hope this helps. regards tim...

      from:
      阅读(1886) | 评论(0) | 转发(0) |
      0

      上一篇:oracle nested table insert

      下一篇:oracle ora-25153

      给主人留下些什么吧!~~
      ")); function link(t){ var href= $(t).attr('href'); href ="?url=" encodeuricomponent(location.href); $(t).attr('href',href); //setcookie("returnouturl", location.href, 60, "/"); }
      网站地图