2010-12-13 58 views
5

我想,如下所示覆制與crontab中類似語義的PostgreSQL數據庫表(mininimal)的crontab功能的PostgreSQL數據庫(指標未顯示,對於simiplicity):運行查詢定期(ALA的crontab)從

create table schedule (
id int not null primary key, 
command text 
); 

create table schedule_detail(
schedule_id int not null references schedule(id), 
sd_minute smallint not null, 
sd_hour smallint not null, 
sd_day smallint not null, 
sd_month smallint not null, 
sd_year smallint not null, 
sd_dayofweek smallint not null 
); 

我只得到模式設計。我想就如何實現這一點提出一些想法。特別是,如何實現:

  1. 在計劃表中的「定期輪詢」
  2. 如何確定的時間表來運行

PostgreSQL擁有任何本機(內置)的功能,我可以建立在實現這種行爲?

回答

8

pgAgent將完成這項工作。完整的設置可以在Postgresonline.com找到。

+0

+1它甚至採用了使用[的cron風格的格式(http://www.pgadmin.org/docs/1.4/pgagent-schedules.html) – 2010-12-14 14:30:31

+0

我決定「推出自己的」因爲pgAgent是我想要的矯枉過正。不過,我會接受這個答案,因爲它讓我走上了正確的道路 – skyeagle 2010-12-15 08:14:19

+0

@skyeagle,我希望看到你的pgAgent版本,你是否用pgsql或不同的腳本語言編寫它? – indago 2013-04-08 14:42:02

1

我一直在使用psql + crontab。像這樣:

此crontab條目將以滾動方式刪除超過60天的內容。

0 16 * * * PGPASSWORD=mypassword psql -Umyuser -dmyschema -c "delete from mytable where created_at < now() - interval '60 days'"