pg_cron icon indicating copy to clipboard operation
pg_cron copied to clipboard

timezone problem

Open idlesysman opened this issue 8 years ago • 13 comments

my db‘s timezone

db=# show timezone ; TimeZone

PRC (1 row)

when i insert some record to cron.job,find that exection time is not the db‘s default timezone(RPC). it seems that using UTC.

idlesysman avatar Jan 03 '17 07:01 idlesysman

Like cron, pg_cron always uses GMT. Would adding a timezone GUC help?

marcocitus avatar Jan 03 '17 10:01 marcocitus

Cron runs in the local time. Could you please make conversion to GTM in pg_cron a configurable option?

dumbuzz avatar Jan 18 '17 14:01 dumbuzz

Just been bitten by this as well. Wouldn't it make more sense for pg_cron times to be the same as reported in localtime? Failing that perhaps it would be better to state the timezone when adding a new cron job so you would have:

SELECT cron.schedule(schedule, command, timezone);

Where timezone would be the pg_timezone_names.abbrev e.g. 'BST'. This would be handy as some pg_cron jobs we run are local time dependent e.g. run at 9:00AM local time but I can imagine a mix in a more geographically distributed environment.

mccuskk avatar Apr 26 '18 12:04 mccuskk

A way to configure the library to use a specific timezone would be really useful.

Especially if you are in a timezone that has daylight savings, like PST. Otherwise, we have to change the schedule of our jobs every time daylight savings changes.

Thanks.

ArcadeRenegade avatar Jun 13 '18 21:06 ArcadeRenegade

We have the same issue. Using localtime would be ok to avoid changes for daylight savings but specify the timezone for each job seems much better as it should cover anything you might need. Any forecast about when a fix could be implemented?

3kkani avatar Jul 13 '18 13:07 3kkani

Any progress about this problem ?

suishaojian avatar Apr 23 '20 16:04 suishaojian

Is there any possibility to configure pg_cron to use local time meanwhile? Also for my use case this would be great.

elkejava avatar Oct 27 '20 09:10 elkejava

Would also need local timezone. Every tine Sommer/Winter time changes, jobs are shifted 1 hour...

Schlumie avatar Apr 05 '21 14:04 Schlumie

Would also need local timezone. Every tine Sommer/Winter time changes, jobs are shifted 1 hour...

I second that.

While it may be beneficial for Postgres server to convert or assume all dates UTC internally, it doesn't work for cron, or for anything really.

Consider SELECT cron.schedule('59 '|| date_part('hour',now()) || ' * * *','SELECT 1') . You'd expect it to run at 59th minute of current hour, but it will actually do so ONLY if you happen to be at UTC.

gnudiff avatar Apr 26 '21 07:04 gnudiff

The logic is use local time zone, the configured in show timezone in postgresql.

cesarjorgemartinez avatar May 17 '21 13:05 cesarjorgemartinez

Having a timzone (or using system) sounds good, but adjusting for summer time is a can of worms - what about jobs scheduled for say 0130, do you want them not to happen at all the day the clocks go forward, and twice on the day they go back? Wouldn't be worth it even if possible/simple to implement IMO.

OJFord avatar Jan 04 '22 11:01 OJFord

This problem isn't new? Normally the last execute time is stored per job to help determine if job already run or didn't run/was skipped due to summer/wintertime change.

Schlumie avatar Jan 04 '22 11:01 Schlumie

our fork https://github.com/hslightdb/pg_cron is tz-aware. in pg_cron--1.4-1--1.5.sql

hslightdb avatar Mar 02 '22 14:03 hslightdb

The problem is still there! :( I use Postgresql 10. pg_cron was builded from repo clone. pg_crone ext version 1.4-1. Inside DB i set +3 GTM, in OS i set local timzeone to +3GMT. Then I restarted db, cron, rsyslog. Rescheduled all my cron.job. But pg_cron still start job at UTC

sv-hmelevsky avatar Nov 02 '22 13:11 sv-hmelevsky

#219 added a cron.timezone, which currently defaults to GMT for backwards compatibility

marcocitus avatar Feb 03 '23 14:02 marcocitus