Exforsys

Home arrow Reviews arrow Oracle 11g Scheduler

Oracle Job Scheduling - Event Based Scheduling - Part 2

Author: Packt Publishing     Published on: 3rd Nov 2009

The following objects show up in the schema, which are created to support the queue table:

Ads

This also explains why MARVIN needs quota on his default tablespace.

The queue definitions part is ready. Now, we can tie a job to the queue. First, create a job as follows:

Sample Code
  1.  
  2. --/
  3. BEGIN
  4. sys.dbms_scheduler.create_job
  5. (
  6. job_name => '"MARVIN"."BCKUP_01"',
  7. job_type => 'EXECUTABLE',
  8. job_action => '/home/oracle/bin/rman.sh',
  9. event_condition => 'tab.user_data.msg=''GO''',
  10. queue_spec => '"MARVIN"."BCKUP_Q"',
  11. start_date => systimestamp at time zone 'Europe/Amsterdam',
  12. job_class => '"LONGER"',
  13. comments => 'backup a database',
  14. auto_drop => FALSE,
  15. number_of_arguments => 1,
  16. enable => FALSE
  17. );
  18. sys.dbms_scheduler.set_attribute
  19. (
  20. name => '"MARVIN"."BCKUP_01"',
  21. attribute => 'raise_events',
  22. value => dbms_scheduler.job_started +
  23. dbms_scheduler.job_succeeded +
  24. dbms_scheduler.job_failed +
  25. dbms_scheduler.job_broken +
  26. dbms_scheduler.job_completed +
  27. dbms_scheduler.job_stopped +
  28. dbms_scheduler.job_sch_lim_reached +
  29. dbms_scheduler.job_disabled +
  30. dbms_scheduler.job_chain_stalled
  31. );
  32. sys.dbms_scheduler.set_job_argument_value
  33. (
  34. job_name => '"MARVIN"."BCKUP_01"',
  35. argument_position => 1,
  36. argument_value => 'db_01'
  37. );
  38. DBMS_SCHEDULER.SET_ATTRIBUTE
  39. (
  40. name => '"MARVIN"."BCKUP_01"',
  41. attribute => 'destination',
  42. value => 'pantzer:15021'
  43. );
  44. DBMS_SCHEDULER.SET_ATTRIBUTE
  45. (
  46. name => '"MARVIN"."BCKUP_01"',
  47. attribute => 'credential_name',
  48. value => '"MARVIN"."JOBS_CRED2"'
  49. );
  50. END;
  51. /
Copyright exforsys.com


This is just a simple remote external job that calls an RMAN script with an argument for the database to back up. As the backup will take longer than a few seconds, it looks obvious to put it in the job_class called LONGER that we defined a while ago. The queue that is coupled to this job is the queue we defined before. It is bckup_q as defined by the queue_spec parameter. As soon as the GO message appears in the payload of the queue, all of the jobs that listen to this queue and those waiting for this GO message will get started. The code listed for the MARVIN job can also be put together using DB Console.

In the following Schedule screen, select Event as Schedule Type:

As the job was not Enabled, it now looks like the following:

So, let's enable the job:

Sample Code
  1. --/
  2. BEGIN
  3. sys.dbms_scheduler.enable( '"MARVIN"."BCKUP_01"' );
  4. END;
  5. /
Copyright exforsys.com


This produces the following:

Ads

The job is currently scheduled, but not on a date. All we need to do now is have someone put a GO message in the bckup_q.

Sample Code
  1. --/
  2. declare
  3. my_msgid RAW(16);
  4. props dbms_aq.message_properties_t;
  5. enqopts dbms_aq.enqueue_options_t;
  6. begin
  7. sys.dbms_aq.enqueue('marvin.bckup_q', enqopts, props,
  8. marvin.bckup_msgt('GO'), my_msgid);
  9. end;
  10. /
  11. commit;
Copyright exforsys.com




 
This tutorial is part of a Oracle 11g Scheduler tutorial series. Read it from the beginning and learn yourself.

Oracle 11g Scheduler

 

Comments