PostgreSQL 中的事件调度程序?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6839469/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Event Scheduler in PostgreSQL?
提问by Mark Harold C. Rivera
Is there a similar event scheduler from MySQL available in PostgreSQL?
PostgreSQL 中是否有来自 MySQL 的类似事件调度程序?
回答by Greg Smith
While a lot of people just use cron, the closest thing to a built-in scheduler is PgAgent. It's a component to the pgAdmin GUI management tool. A good intro to it can be found at Setting up PgAgent and doing scheduled backups.
虽然很多人只使用 cron,但最接近内置调度程序的是 PgAgent。它是 pgAdmin GUI 管理工具的一个组件。一个很好的介绍可以在设置 PgAgent 和执行计划备份中找到。
回答by Fares Younis
pg_cronis a simple, cron-based job scheduler for PostgreSQL that runs inside the database as an extension. A background worker initiates commands according to their schedule by connecting to the local database as the user that scheduled the job.
pg_cron can run multiple jobs in parallel, but it runs at most one instance of a job at a time. If a second run is supposed to start before the first one finishes, then the second run is queued and started as soon as the first run completes. This ensures that jobs run exactly as many times as scheduled and don't run concurrently with themselves.
If you set up pg_cron on a hot standby, then it will start running the cron jobs, which are stored in a table and thus replicated to the hot standby, as soon as the server is promoted. This means your periodic jobs automatically fail over with your PostgreSQL server.
pg_cron是一个简单的、基于 cron 的 PostgreSQL 作业调度程序,它作为扩展在数据库内部运行。后台工作人员通过作为调度作业的用户连接到本地数据库,根据他们的调度启动命令。
pg_cron 可以并行运行多个作业,但它一次最多运行一个作业实例。如果第二次运行应该在第一次运行完成之前开始,那么第二次运行会排队并在第一次运行完成后立即开始。这可确保作业按计划运行的次数完全相同,并且不会与它们自己同时运行。
如果您在热备用上设置 pg_cron,那么一旦服务器升级,它将开始运行 cron 作业,这些作业存储在表中并因此复制到热备用。这意味着您的定期作业会自动通过 PostgreSQL 服务器进行故障转移。
Source: citusdata.com
资料来源:citusdata.com