Here is my take on it:
- make sure pgAgent is installed
- I spent some time searching, but could not find a user interface for pgAgent on Windows for Postgres 9.1. Apparently, some existed in earlier versions - but for this I had to write some SQL manually
SET search_path = pgagent;
INSERT INTO pga_jobclass VALUES (6, 'Scheduled Tasks');
INSERT INTO pga_job VALUES (5, 6, 'TableReindex', 'Reindex tables', '', true,
'2013-03-07 10:00:00.000+11', --date created
'2013-03-07 10:00:00.000+11', --date changed
NULL, NULL, NULL);
INSERT INTO pga_schedule VALUES (3, 5, 'TableReindexSchedule', 'Reindex tables',
true, --enabled
'2013-03-07 10:00:00.000+11', --start date
NULL, --end (never)
'{t,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f}', --minutes: 't' for run on the first minute of an hour
'{t,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f}', --hours: 't' to run at 3 AM
'{f,f,f,f,f,f,f}', -- weekdays: don't care, all false
'{t,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f}', -- monthdays: 't' to run on the first day
'{t,t,t,t,t,t,t,t,t,t,t,t}'); -- months: all true to run on the first day on each month
INSERT INTO pga_jobstep VALUES (5, 5, 'TableReindexInfo', '', true, 's', 'REINDEX TABLE mytable1;REINDEX TABLE mytable2;', '', '@@DATABASE_NAME@@', 'f', NULL);
As a check, the jobnextrun is set to '2013-04-01 03:00:00+11' in pga_job table after running the script.