Why doesn't pgAgent run my job every minute? I have a job and I set the schedule to run every minute.



However, it always skips the next minute after finishing the process, even when the process ends in less than one minute.



The problem is that data is still arriving during that minute so when the job starts, it has to process two minutes of data. I'd rather have two 15 seconds runs, than one long 30 seconds run.

How can I make pgAgent run every minute?

In other cases when I set the schedule to every 3 minutes, pgAgent skips the 4th minute and starts on the 5th.
pgAgent updates the pgagent.pga_job row for the job once the scheduled job completes.  pgAgent will then only run the job a minimum of 1 minute later.  The thread for jobs that are scheduled to run "every minute" looks for new jobs to run once per minute, at the start of each minute.  So, if your job completes at 13:01:26, the next time the schedule runs will be 13:02:00, however since the job completed 34 seconds ago, it does not run the job.  The next time the scheduler runs, at 13:03:00, it sees the job ran more than one minute ago, and runs the job.

The pgAgent source code for pgagent.pga_next_schedule notes this:

-- Get the time to find the next run after. It will just be the later of
-- now() + 1m and the start date for the time being, however, we might want to
-- do more complex things using this value in the future.
IF date_trunc(''MINUTE'', jscstart) &gt; date_trunc(''MINUTE'', (now() + ''1 Minute''::interval)) THEN
    runafter := date_trunc(''MINUTE'', jscstart);
ELSE
    runafter := date_trunc(''MINUTE'', (now() + ''1 Minute''::interval));
END IF;