Exforsys.com
 

Sponsored Links

 

Oracle Scheduler Tutorials

 
Home Tutorials Oracle Scheduler
 

Oracle Job Scheduling - Event Based Scheduling - Part 1

 

On many occasions, a calendar will do fine for scheduling jobs. However, there are situations that require an immediate action and which cannot wait for the next activation based on a calendar. An example might be of a user who logs on to the database and then, using a logon trigger, more actions are executed.



Another example could be a situation in which we want a backup server to be utilized to the maximum, but not beyond that. We schedule all the backups independent of each other and have each backup raise an event when ready, which tells the system that another backup can go ahead. By letting the backup jobs wait for an event that essentially flags "there is backup capacity available now", we make sure that a backup does not take longer than needed. We also make sure that the backup system is pushed to the highest throughput.


When we just use a preset date and time to start the backups, chances are that more backups are running at the same time (possibly caused by the growth of one or more databases, which is potentially causing their backups to be longer than anticipated). On the other hand, when we make sure that more backups are never ever run at the same time, we will likely have lots of idle time in the backup system.


This is a reason enough to learn how we can make good use of events. However, there are a few things we need to do. It essentially comes down to:
• Creating a queue and defining a payload for that queue
• Having a process that puts the message on the queue
• Coupling one or more job definition(s) to the queue


Again, this gives a kind of control that is hard to find in third-party scheduling packages.


Event messages are placed on an event queue and this is handled by AQ. So we need to call the AQ packages and for that we require DBMS_AQ and DBMS_AQADM. In the days before Oracle 10g, we needed to set the AQ_TM_PROCESSES parameter to a non-zero value to work. Since Oracle 10g, this is no longer the case and we can leave the AQ_TM_PROCESSES value to zero.


First, make sure we can use AQ.


Sample Code
  1. SELECT grantee, privilege, table_name
  2. FROM dba_tab_privs
  3. WHERE table_name IN ( 'DBMS_AQ', 'DBMS_AQADM')
  4. AND grantee = 'MARVIN';
  5. /
Copyright exforsys.com


The expected output is as shown in the following screenshot:



If this query does not show MARVIN having the EXECUTE privileges on both DBMS_AQ and DBMS_AQADM, we need to give them to our user.
As a DBA, execute the following:


Sample Code
  1. GRANT execute ON dbms_aq TO marvin;
  2. GRANT execute ON dbms_aqadm TO marvin;
  3. GRANT SELECT ON dba_aq_agents TO marvin; GRANT CREATE type TO marvin;
  4. ALTER user marvin quota unlimited ON users;
  5. --/
  6. begin
  7. dbms_aqadm.grant_system_privilege ('ENQUEUE_ANY', 'marvin', FALSE);
  8. dbms_aqadm.grant_system_privilege ('DEQUEUE_ANY', 'marvin', FALSE);
  9. dbms_aqadm.grant_system_privilege ('MANAGE_ANY', 'marvin', TRUE);
  10. end;
  11. /
Copyright exforsys.com


This makes sure that marvin has enough privileges to be able to create and use queues. Now connect as marvin, create an object type that we can use to put a message on the queue, and read from the queue later on.


Sample Code
  1. connect marvin/panic
  2. CREATE OR REPLACE type bckup_msgt AS object ( msg varchar2(20) )
  3. /
Copyright exforsys.com


This defines a type consisting of one msg field of 20-character length. This is the type we will be using in the queue for which we create a queue table next:


Sample Code
  1. --/
  2. begin
  3. dbms_aqadm.create_queue_table
  4. (
  5. queue_table => 'bckup_qt',
  6. queue_payload_type => 'bckup_msgt',
  7. multiple_consumers => TRUE
  8. ) ;
  9. dbms_aqadm.create_queue
  10. (
  11. queue_name => 'bckup_q',
  12. queue_table => 'bckup_qt'
  13. ) ;
  14. dbms_aqadm.start_queue ( queue_name => 'bckup_q' ) ;
  15. end ;
  16. /
Copyright exforsys.com



This creates a queue table called bckup_qt, which contains messages defined by bckup_msgt. After that, bckup_q starts immediately.



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



 

 

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 - 2009 exforsys.com. All Rights Reserved

Page copy protected against web site content infringement by Copyscape