Mohamed Houri’s Oracle Notes

April 26, 2012

DBMS_SCHEDULER and Winter/Summer time

Filed under: Oracle — hourim @ 10:50 am

Recently we have created a scheduled job via the Oracle dbms_scheduler package that resembles to:

BEGIN
  dbms_scheduler.create_job (
    job_name        => 'TEST_TIME_ZONE_JOB',
    job_type        => 'PLSQL_BLOCK',
    job_action      => 'BEGIN NULL; END;',
    start_date      => systimestamp ,
    repeat_interval => 'freq=daily; byhour=6; byminute=0; bysecond=0;' ,
    end_date        => NULL,
    enabled         => true,
    comments        => 'Job defined to test the effect of time zone in the job start.'
   );
END;
/

This job has been created to start every day at 06H00. Let’s then check what will be the next start date of this job

SQL> select
  2         job_name
  3        ,start_date
  4        ,next_run_date
  5  from
  6        user_scheduler_jobs
  7  where
  8        job_name ='TEST_TIME_ZONE_JOB';

JOB_NAME           START_DATE	     	       NEXT_RUN_DATE
------------------ ----------------------------------- ------------------------------------
TEST_TIME_ZONE_JOB 26-APR-12 11.44.55.610357 AM +02:00  27-APR-12 06.00.00.600000 AM +02:00

What? It will start at 6 AM + 02:00 ??? That’s not what I wanted.

Do you know from where this discrepancy comes? It comes from the job which has been scheduled without taking into account the local time zone. In order to solve this problem, you can re-create your job appropriately as follows

SQL> begin
  2    dbms_scheduler.drop_job('TEST_TIME_ZONE_JOB');
  3  end;
  4  /

PL/SQL procedure successfully completed.

SQL> BEGIN
  2    dbms_scheduler.create_job (
  3      job_name        => TEST_TIME_ZONE_JOB',
  4      job_type        => 'PLSQL_BLOCK',
  5      job_action      => 'BEGIN NULL; END;',
  6      start_date      => systimestamp at time zone 'EUROPE/PARIS', --> here is the difference
  7      repeat_interval => 'freq=daily; byhour=6; byminute=0; bysecond=0;' ,
  8      end_date        => NULL,
  9      enabled         => true,
 10      comments        => 'Job defined to test the effect of time zone in the job start.'
 11     );
 12  END;
 13  /

PL/SQL procedure successfully completed.

SQL> select
  2         job_name
  3        ,start_date
  4        ,next_run_date
  5  from
  6        user_scheduler_jobs
  7  where
  8        job_name ='TEST_TIME_ZONE_JOB';

JOB_NAME           START_DATE                                NEXT_RUN_DATE
------------------ ----------------------------------------  -----------------------------------------
TEST_TIME_ZONE_JOB 26-APR-12 11.46.02.075991 AM EUROPE/PARIS 27-APR-12 06.00.00.100000 AM EUROPE/PARIS

As such, the next run date is scheduled exactly as the desired time (06H00).
The DBA can also set the dbms_scheduler parameter so that the appropriate time zone (‘EUROPE/PARIS’, in my case) could be set as a default value:

begin
   dbms_scheduler.set_scheduler_attribute('DEFAULT_TIMEZONE', 'EUROPE/PARIS’);
end;

I hope this simple article will help avoiding such a kind of automatic change in the start time of a scheduled job when there is a shift between winter/summer time.

1 Comment »

  1. Excellent website, thanks for share this article with us

    Comment by Sherri Oestreicher — May 21, 2012 @ 5:16 pm | Reply


RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Blog at WordPress.com.

Tony's Oracle Tips

Tony Hasler's light hearted approach to learning about Oracle

Richard Foote's Oracle Blog

Focusing Specifically On Oracle Indexes, Database Administration and Some Great Music

Hatem Mahmoud Oracle's blog

Just another Oracle blog : Database topics and techniques

Mohamed Houri’s Oracle Notes

Qui se conçoit bien s’énonce clairement

Oracle Diagnostician

Performance troubleshooting as exact science

Raheel's Blog

Things I have learnt as Oracle DBA

Coskan's Approach to Oracle

What I learned about Oracle

So Many Oracle Manuals, So Little Time

“Books to the ceiling, Books to the sky, My pile of books is a mile high. How I love them! How I need them! I'll have a long beard by the time I read them”—Lobel, Arnold. Whiskers and Rhymes. William Morrow & Co, 1988.

EU Careers info

Your career in the European Union

Carlos Sierra's Tools and Tips

Tools and Tips for Oracle Performance and SQL Tuning

Oracle Scratchpad

Just another Oracle weblog

OraStory

Dominic Brooks on Oracle Performance, Tuning, Data Quality & Sensible Design ... (Now with added Sets Appeal)

%d bloggers like this: