下面將創建一個運行的每一分鐘,與調用一些SQL的一個步驟的工作:
do $$
declare
job_id int;
begin
/* add a job and get its id: */
insert into
pgagent.pga_job (jobjclid, jobname)
values
(1 /*1=Routine Maintenance*/, 'my job name')
returning
jobid
into
job_id;
/* add a step to the job: */
insert into
pgagent.pga_jobstep (jstjobid, jstname, jstkind, jstcode, jstdbname)
values
(
job_id,
'my step name',
's', /* sql step */
'select * from thing', /* the sql to run */
'mydb' /* the name of the database to run the step against */
);
/* add a schedule to the job. This one runs every minute: */
insert into
pgagent.pga_schedule (jscjobid, jscname)
values
(job_id, 'my schedule name');
end $$;