如何防止 Sql Server 作业同时运行

2024-04-15数据库问题
1

本文介绍了如何防止 Sql Server 作业同时运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我的 SQL 代理中有一些预定的作业:

I have some scheduled jobs in my SQL Agent:

  • Job1,每 2 分钟执行一次
  • Job2,每 10 分钟执行一次
  • Job3,每 15 分钟执行一次

如您所见,多个作业可以同时运行.当这些作业同时运行时,会导致 CPU 使用率达到 100%.

As you can see, multiple jobs can run simultaneously. When these jobs do run simultaneously, it is causing the CPU usage to go to 100%.

有解决办法吗?有没有办法控制并发运行的作业数量?注意:我需要这些作业在适当的时间内大约运行.

Is there a solution? Is there a way to control the number of jobs running concurrently? Note: I need these jobs to run approximately in their appropriate period.

推荐答案

通过 sp_getapplock

您要求用户控制并发,这通常是最好的方法.

You're asking for user-controlled concurrency and this is usually the best way.

这允许您在锁已被另一个作业持有时等待或中止.我们在一两个地方使用它来阻止多个用户强迫同一任务重叠运行.效果很好.

This allows you to wait or abort if the lock is already held by another job. We use it in one or 2 places to stop multiple users forcing the same task to run overlapping. It works well.

这篇关于如何防止 Sql Server 作业同时运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

The End

相关推荐

按天分组的 SQL 查询
SQL query to group by day(按天分组的 SQL 查询)...
2024-04-16 数据库问题
77

在 Group By 查询中包含缺失的月份
Include missing months in Group By query(在 Group By 查询中包含缺失的月份)...
2024-04-16 数据库问题
12

sql group by 与不同
sql group by versus distinct(sql group by 与不同)...
2024-04-16 数据库问题
37

如何在SQL中返回每个组的增量组号
How to return a incremental group number per group in SQL(如何在SQL中返回每个组的增量组号)...
2024-04-16 数据库问题
8

统计分组返回的记录数
Count number of records returned by group by(统计分组返回的记录数)...
2024-04-16 数据库问题
10

带聚合函数的 SQL GROUP BY CASE 语句
SQL GROUP BY CASE statement with aggregate function(带聚合函数的 SQL GROUP BY CASE 语句)...
2024-04-16 数据库问题
23