390 likes | 471 Views
DBMS_SCHEDULER: The How, What and Why. David Hicken Flying J, Inc. david.hicken@flyingj.com. Event Driven Schedules DBMS_JOBS to DBMS_SCHEDULER Monitoring the Scheduler Things to Look Out For Q & A. Oracle DBMS_SCHEDULER. Scheduling Options DBMS_Scheduler Options
E N D
DBMS_SCHEDULER:The How, What and Why David Hicken Flying J, Inc. david.hicken@flyingj.com
Event Driven Schedules DBMS_JOBS to DBMS_SCHEDULER Monitoring the Scheduler Things to Look Out For Q & A Oracle DBMS_SCHEDULER • Scheduling Options • DBMS_Scheduler Options • Breaking Down the DBMS_SCHEDULER • Individual parts of the DBMS_SCHEDULER • Time Driven Schedules
Oracle Scheduling Options • Cron and at in Unix and Linux • Windows Scheduler • DBMS_JOBS • Oracle Scheduler • Oracle 9i Scheduler • Oracle 10g Scheduler • Oracle 11g Scheduler
DBMS_Scheduler Options • Time Driven Schedules • Flexible and Easy • Event Driven Schedules • Harder to set up • Chaining Schedules • Can be used with Time or Event
Breaking Down DBMS_Scheduler • Programs • Schedules • Jobs • Job Classes • Windows • Window Groups • Chains
DBMS_SCHEDULER: Programs • Stored Procedure • Can pass parameters • PL/SQL Block • Executable • Dependent upon the OS.
DBMS_SCHEDULER: Schedules • Named Schedules • On the fly • Can use old DBMS_JOBS scheduling syntax, or new syntax. • EVALUATE_CALENDAR_STRING
BYMONTH BYDAY BYHOUR BYMINUTE BYSECOND BYWEEKNO BYDATE BYMONTHDAY INCLUDE DBMS_SCHEDULERSchedule words • FREQ • Yearly • Monthly • Weekly • Hourly • Minutely • Secondly • INTERVAL • Number And many others!
DBMS_SCHEDULER: Jobs begin dbms_scheduler.create_job ( job_name => 'HR_STATS_REFRESH', job_type => 'PLSQL_BLOCK', job_action => '- - Gather HR Stats BEGIN DBMS_STATS.GATHER_SCHEMA_STATS(''hr''); END;', start_date => systimestamp, repeat_interval => 'FREQ=DAILY';byhour=9;byminute=0, enabled => TRUE, comments => 'Refreshes the HR Schema at 9:00 PM' ); end; /
DBMS_SCHEDULER: Job Classes • Create Job Class to group jobs • Assign Resources to Job Class • Control Jobs according to Class • Start and Stop a group of jobs • Set Priorities for a Job Class
DBMS_SCHEDULER: Windows • Caution: Windows are NOT schedules • Only one window open at a time • When windows conflict, Priority and “First Open” • Stop on Window Close • Force Windows to Open and/or Close
DBMS_SCHEDULER:Window Groups • Combine Windows • Weeknights • Weekends MAINTENANCE_WINDOW
DBMS_SCHEDULER:Event Driven Schedules • Requires Advanced Queuing • Defined Events • More advanced than this class ....
JOB_DISABLED JOB_CHAIN_STALLED JOB_OVER_MAX_DURATION Events raised by applications DBMS_SCHEDULER Events • JOB_STARTED • JOB_SUCCEEDED • JOB_FAILED • JOB_BROKEN • JOB_COMPLETED • JOB_STOPPED • JOB_SCH_LIM_REACHED
DBMS_SCHEDULER:Chains • Can be Time Driven or Event Driven • Define Programs • Define Steps • A program • Another chain (nested chain) • An Event
Monitoring and Managingthe Scheduler • Oracle Enterprise Manager • Straight forward, but many screens deep • Toad • Implemented poorly in current versions, but next version (Toad 10) is greatly improved • DBA_ Views
DBA_QUEUE_SCHEDULES DBA_SCHEDULER_JOB_ARGS DBA_SCHEDULER_WINDOW_LOGDBA_SCHEDULER_RUNNING_CHAINS DBA_SCHEDULER_GLOBAL_ATTRIBUTE DBA_SCHEDULER_WINDOW_GROUPS DBA_SCHEDULER_PROGRAMS DBA_SCHEDULER_JOB_CLASSES DBA_SCHEDULER_JOB_LOG DBA_SCHEDULER_CHAIN_RULES DBA_SCHEDULER_CHAINS Scheduler DBA_ Views • DBA_SCHEDULER_JOBS • DBA_SCHEDULER_PROGRAM_ARGS • DBA_SCHEDULER_WINGROUP_MEMBERS • DBA_SCHEDULER_SCHEDULES • DBA_SCHEDULER_WINDOWS • DBA_SCHEDULER_JOB_RUN_DETAILS • DBA_SCHEDULER_WINDOW_DETAILS • DBA_SCHEDULER_RUNNING_JOBS • DBA_SCHEDULER_CHAIN_STEPS
Things to Watch for... • OEM has trouble defining schedules • Toad's implementation is poor • Bug in creating programs. Test run script first • Uses TIMESTAMP, which has a bug prior to 10.2.0.4. Makes it hard to see when schedules fire • Some of the DBA_ views may require some “tweaking” due to above bug • ALTER SYSTEM SET job_queue_processes=0; doesn't stop schedules!
DBMS_Scheduler vs. DBMS_Jobs • More versatile scheduling • Scheduling syntax is readable • Event driven ability • Chaining ability • Enable/Disable • Easily editable • Parameters • Logging • … and that's the ones off the top of my head.
Converting DBMS_JOBS toDBMS_SCHEDULER • Can use old syntax trunc(sysdate)+1+3/24 • Can use new syntax freq=daily;interval=1;byhour=3;byminute=24 • Caution with self-replicating DBMS_JOBS
Questions? DBMS_SCHEDULERThe How What and Why