citusdata / pg_cron

Run periodic jobs in PostgreSQL
PostgreSQL License
2.79k stars 189 forks source link

Job scheduled to run every minute not running every minute #251

Open SteveDirschelTR opened 1 year ago

SteveDirschelTR commented 1 year ago

Environment/Setup:

Aurora Postgres.

dbtest=> select version(); version

PostgreSQL 14.5 on x86_64-pc-linux-gnu, compiled by x86_64-pc-linux-gnu-gcc (GCC) 7.4.0, 64-bit (1 row)

dbtest=> select name, setting from pg_settings where name like '%cron%'; name | setting -----------------------------+----------- cron.database_name | dbtest cron.enable_superuser_jobs | on cron.host | localhost cron.log_min_messages | warning cron.log_run | on cron.log_statement | off cron.max_running_jobs | 5 cron.use_background_workers | on (8 rows)

dbtest=> select name, setting from pg_settings where name = 'max_parallel_workers'; name | setting ----------------------+--------- max_parallel_workers | 8 (1 row)

dbtest=> select from cron.job; jobid | schedule | command | nodename | nodeport | database | username | active | jobname -------+--------------+------------------------------------------------------------------------------+-----------+----------+----------+----------+--------+--------------------- 4 | 0 19 | call perf.snap_purge() | localhost | 5432 | dbtest | postgres | t | Stats Purge 5 | 0 0 | DELETE FROM cron.job_run_details WHERE end_time < now() - interval '7 days'; | localhost | 5432 | dbtest | postgres | t | Cron_Purge 34 | | call perf.snap_ash() | localhost | 5432 | dbtest | postgres | t | inute ASH Snap 36 | | call perf_ro1.snap_ash() | localhost | 5432 | dbtest | postgres | t | inute ASH Snap RO_1 38 | 0 19 | call perf_ro1.snap_purge() | localhost | 5432 | dbtest | postgres | t | tats Purge RO_1 42 | /15 | call perf.snap_stats() | localhost | 5432 | dbtest | postgres | t | tats Snap 67 | /15 | call perf_ro1.snap_stats() | localhost | 5432 | dbtest | postgres | t | tats Snap RO_1

I will focus on jobid 34- call perf.snap(). This function will snap pg_stat_activity every second for 59 seconds and then stop.

Here are start_time and end_time of that job looking at cron.job_run_details. It was getting kicked off on the top of each minute as expected.

2023-03-14 12:08:00.356066 2023-03-14 12:09:00.209217 2023-03-14 12:09:00.215034 2023-03-14 12:10:00.093877 2023-03-14 12:10:00.103044 2023-03-14 12:10:59.588175

But then suddenly the start time stopped starting it on the top of each minute: 2023-03-14 12:11:59.465251 2023-03-14 12:13:58.793234 2023-03-14 12:12:58.922721 2023-03-14 12:14:58.279701 2023-03-14 12:15:58.16635 2023-03-14 12:16:57.64259 2023-03-14 12:17:57.50315 2023-03-14 12:18:56.959171 It is like it suddenly started executing 1 minute after the prior execution completed and not every minute.

This is a test server and there is not a whole lot of activity going on other then these cron jobs. What would make it suddenly stop getting executed at the top of every minute but it seems more like it changed to the end of the prior job plus 1 minute?

Thanks

SteveDirschelTR commented 1 year ago

Forgot to add- the version of the extension we are on is 1.3