2014-03-19 62 views
0

我有一个SQL Sever 2008 R2数据库安装程序和一个每小时运行一次查询(大约需要3分钟运行)的查询。该查询用其结果填充临时表。复制SQL Server数据库死锁查询受害者

然而,每隔一段时间我得到这个错误:

Transaction (Process ID 63) was deadlocked on lock resources with another process and has been chosen as the deadlock victim. Rerun the transaction. [SQLSTATE 40001] (Error 1205)

这将停止正在运行的查询。

处理此错误的最佳做法是什么?

在此先感谢。

exec sp_executesql N'EXECUTE msdb.dbo.sp_sqlagent_log_jobhistory @job_id = @P1, @step_id = @P2, @sql_message_id = @P3, @sql_severity = @P4, @run_status = @P5, @run_date = @P6, @run_time = @P7, @run_duration = @P8, @operator_id_emailed = @P9, @operator_id_netsent = @P10, @operator_id_paged = @P11, @retries_attempted = @P12, @session_id = @P13, @message = @P14',N'@P1 uniqueidentifier,@P2 int,@P3 int,@P4 int,@P5 int,@P6 int,@P7 int,@P8 int,@P9 int,@P10 int,@P11 int,@P12 int,@P13 int,@P14 nvarchar(4000)','0A7AFD76-D2EC-463E-A802-8B66241B0D26',2,8153,13,0,20140320,110114,219,0,0,0,0,52,N'Executed as user: DOMAIN\sql. Transaction (Process ID 62) was deadlocked on lock resources with another process and has been chosen as the deadlock victim. Rerun the transaction. [SQLSTATE 40001] (Error 1205) Warning: Null value is eliminated by an aggregate or other SET operation. [SQLSTATE 01003] (Error 8153). The step failed.'

上面是返回表单分析器。

+0

是否有任何其他的工作修改您的查询访问表? –

+0

@ shree.pat18我可以建议的唯一事情是复制本身? – LaLa

回答

2

您需要调查造成死锁的原因。解决方案将完全取决于您找到的内容。

注意,如果你扫描一个表,而被更新死锁是非常:关于这个问题的一些读 l ikely。对复制代理主动修改的数据进行“3分钟”查询可能就是这种情况。理想情况下,您的查询应该优化为仅读取相关数据(例如自上次读取后发生了什么变化)。出一个廉价的方式就是启用版本的数据库,阅读Implementing Snapshot or Read Committed Snapshot Isolation in SQL Server: A Guide

ALTER DATABASE <dbname> SET READ_COMMITTED_SNAPSHOT ON; 
+0

Im 99%肯定它是复制,我没有提到的是死锁发生在订阅数据库而不是发布者(我不知道这是否有帮助)。 – LaLa

+1

完全不相关。僵局是死锁是僵局。阅读链接的文章。捕获死锁图。 –

+0

我已编辑原始帖子,更多信息。 – LaLa