0

我有一个代理作业设置为从凌晨 2:00 到晚上 11:59 每两小时运行一次日志备份(留下一个运行完整或差异备份的窗口)。在我的大约 50 个实例中,每一个都设置了类似的工作。随着时间的推移,我可能会添加数百个实例(我们为一些客户托管 SQL Server)。它们都备份到同一个 SAN 磁盘卷。这会导致延迟问题并以其他方式影响性能。

我想将每个实例的作业运行时间偏移 5 分钟,以便实例 1 将在 2:00、4:00 等运行作业,实例 2 将在 2:05、4:05 运行它等,实例 3 将在 2:10、4:10 等运行它,依此类推。如果我在每个实例上偏移作业的开始时间(例如 2:00,例如 2:05,例如 2:10,等等),我可以合理地期望我会得到我想要的结果没有让所有实例同时运行作业?

4

2 回答 2

2

If this is the same conversation we just had on twitter: when you tell SQL Server Agent to run every n minutes or every n hours, the next run is based on the start time, not the finish time. So if you set a job on instance 1 to run at 2:00 and run every 2 hours, the 2nd run will run at 4:00, whether the first run took 1 minute, 12 minutes, 45 minutes, etc.

There are some caveats:

  • there can be minor delays due to internal agent synchronization, but I've never seen this off by more than a few seconds
  • if the first run at 2:00 takes more than 2 hours (but less than 4 hours), the next time the job runs will be at 6:00 (the 4:00 run is skipped, it doesn't run at 4:10 or 4:20 to "catch up")

There was another suggestion to add a WAITFOR to offset the start time (and we should discard random WAITFOR, because that is probably not what you want - random <> unique). If you want to hard-code a different delay on each instance (1 minute, 2 minutes, etc.) then it is much more straightforward to do that with a schedule than by adding steps to all of your jobs. IMHO.

于 2013-08-28T17:58:41.423 回答
0

也许您可以设置一个集中式数据库来管理“计划”并让作业在运行时添加/更新一行。这样,每个后续服务器都可以在可以启动时启动“轮询”的作业。这样,作业中的任何延迟都会导致其他作业等待,因此当其中一台服务器被关闭时,您的时间不会有差异。

作为一个有点偏执的我会添加一个包罗万象的场景,在“x”分钟的等待之后继续进行,这样延迟就不会级联到足以导致作业无法运行的程度。

于 2013-08-28T17:42:17.153 回答