Book Image

Mastering Oracle Scheduler in Oracle 11g Databases

By : Ronald Rood
Book Image

Mastering Oracle Scheduler in Oracle 11g Databases

By: Ronald Rood

Overview of this book

Scheduler (DBMS_SCHEDULER) is included in Oracle Database and is a tool for the automation, management, and control of jobs. It enables users to schedule jobs running inside the database such as PL/SQL procedures or PL/SQL blocks, as well as jobs running outside the database like shell scripts. Scheduler ensures that jobs are run on time, automates business processes, and optimizes the use of available resources. You just need to specify a fixed date and time and Scheduler will do the rest. What if you don't know the precise time to execute your job? Nothing to worry about, you can specify an event upon which you want your job to be done and Scheduler will execute your job at the appropriate time. Although scheduling sounds quite easy, it requires programming skills and knowledge to set up such a powerful, intelligent scheduler for your project. This book is your practical guide to DBMS_SCHEDULER for setting up platform-independent schedules that automate the execution of time-based or event-based job processes. It will show you how to automate business processes, and help you manage and monitor those jobs efficiently and effectively. It explains how Scheduler can be used to achieve the tasks you need to make happen in the real world. With a little understanding of how the Scheduler can be used and what kind of control it gives, you will be able to recognize the real power that many known enterprise-class schedulers ñ with serious price tags ñ cannot compete with. You will see how running a specific program can be made dependent on the successful running of certain other programs, and how to separate various tasks using the built-in security mechanisms. You will learn to manage resources to balance the load on your system, and gain increased database performance.
Table of Contents (15 chapters)
Mastering Oracle Scheduler in Oracle 11g Databases
About the Author
About the Reviewers

Statistics collection

From Oracle 10g onwards, Oracle has included a job that automatically collects optimizer statistics for us. So, there is no real need to make such a process again. It might look like inventing a different-colored wheel, but it can be useful if you want more control on how the statistics are collected.

For this, we will make a simple package named sched_stats. As many readers are more than likely to be still using Oracle 10g, the code that we will use is compatible for Oracle 10g as well as 11g. The package has the following four procedures:

  • schedule_run

  • run

  • statob

  • Drop_jobs

The schedule_run procedure

The Schedule_run procedure creates the job that is actually scheduled on a twice-daily basis and has all the parameters with defaults that can be overridden:

procedure schedule_run
( jobclass in varchar2 default 'DEFAULT_JOB_CLASS',
jobname in varchar2 default 'run_stats',
sjobprefix in varchar2 default 'stats_',
repinterval in varchar2 default'FREQ=DAILY;BYHOUR=5,17;BYMINUTE=4...