Exforsys.com
 

Sponsored Links

 

Oracle Scheduler Tutorials

 
Home Tutorials Oracle Scheduler
 

Oracle Job Scheduling - Event Based Scheduling - Part 2

 

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




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:




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



Read Next: Oracle Job Scheduling - Event Based Scheduling - Part 3



 

 

Comments



Post Your Comment:

Members Please Login
Your Name:*
e-mail ID:(required for notification)*
Image Verification: 
 
 Subscribe    

Sponsored Links

 

Subscribe via RSS


Get Daily Updates via Subscribe to Exforsys Free Training via email


Get Latest Free Training Updates delivered directly to your Inbox...

Enter your email address:


 

Subscribe to Exforsys Free Training via RSS
 

 
Partners -  Privacy and Legal Policy -  Site News -  Contact   Sitemap  

Copyright © 2000 - 2010 exforsys.com. All Rights Reserved

Page copy protected against web site content infringement by Copyscape