SQL Server 2008 R2 中的死锁

发布于 2024-11-29 02:12:03 字数 779 浏览 0 评论 0原文

服务器:SQL Server 2008R2 客户端:Excel/ADO - 8 个客户端 服务器硬件:8 核/16GB 内存/操作系统:WinServer 2008SR2

插入/更新和合并/匹配存储过程均发生死锁。

我在这里阅读了很多有关插入/更新的内容,因此,我已将插入/更新更改为合并/匹配,但我仍然从运行的 8 个客户端中收到非常频繁的死锁错误(大约每 10 分钟一次)批处理模式要求以每分钟 2 次的速度进行更新。

相比之下,每个客户端每分钟向另一个表插入大约 20,000 个项目,完全没有问题。

我希望得到一些帮助来解决这些死锁问题,因为我认为这么少的 8 个客户端(尤其是 Excel/ADO/VBA)应该无法给这个数据库带来压力!

另请注意,我不直接通过客户端发出任何 SQL 命令,所有 sql 命令都是通过存储过程调用的。

我现在的SP:

merge [dbo].[File_Level_Data] as TargetMerge
    using(select @Name_of_File as name)as source
    on (TargetMerge.Name_of_File = source.name)

when matched then
    update
    set
    XXX1  = @XXX1, 
    ZZZ25 = @ZZZ25
when not matched then
    insert
    (XXX1,
    ZZZ25
    ) values 
    (
    @XXX1,
    @ZZZ25

);

Server: SQL Server 2008R2
Clients: Excel/ADO - 8 clients
Server hardware: 8 core/16GB Memory/OS:WinServer 2008SR2

Deadlocks happening on both Insert/Update and Merge/Matched stored procedures.

I have read much on here about insert/updating, and as a result, I have changed my Insert/Updates to Merge/Matched, but I am still getting VERY frequent Deadlock errors (about once every 10 minutes) from just 8 clients running in batch mode calling for updates at a rate of 2 per minute.

In contrast, each client inserts about 20,000 items per minute to another table with no issues at all.

I would love some assistance on solving these deadlock issues as I don't think such a measly 8 clients (especially Excel/ADO/VBA) should be able to stress out this DB!

Also note that I do not issue any SQL commands directly through the clients, all sql commands are called through stored procedures.

My current SP:

merge [dbo].[File_Level_Data] as TargetMerge
    using(select @Name_of_File as name)as source
    on (TargetMerge.Name_of_File = source.name)

when matched then
    update
    set
    XXX1  = @XXX1, 
    ZZZ25 = @ZZZ25
when not matched then
    insert
    (XXX1,
    ZZZ25
    ) values 
    (
    @XXX1,
    @ZZZ25

);

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

八巷 2024-12-06 02:12:03

我的僵局是由几年前我放在那里的触发器引起的,但我不相信它们仍然在那里。一旦我删除它们,就不会再出现僵局。

My deadlocks were being caused by a trigger that I had put in there years ago but didn't believe they were still there. Once I removed them, no more deadlocks.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文