SQL Server服务代理的消息已删除错误


我曾经看到这样一个关于服务代理的问题,也许其他人也看到过的:消息被发送到服务代理,接着进行正常的处理,然后它们会从消息队列中删除。然而你仍然能够在sys.conversation_endpoints DMV中看到该会话仍处于“会话中(CONVERSING)”状态,而不是“关闭(CLOSED)”状态。而在sys.transmission_queue并没有相应的记录,这是非常奇怪的。同时,当我们使用SQL Server Profiler检查时也不会发现错误。

  很明显这是一个已知问题。但奇怪的是在我的系统中,它只发生在数据库的一个队列里。

  目前唯一的措施就是对该会话做一个中止并清除(END CONVERSATION WITH CLEANUP)的操作。我已经写了一个脚本用于清除会话。脚本中我专门做了判断,它只清除有问题的会话中的消息,这些会话是当前不在队列中的(这个队列不是自动处理的,有一个服务会每隔30秒检查一次队列,所以这样就能够保留队列中一些我不想删除的有效消息)。


Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

-->declare @i int
set @i = 1
while @i <> 10000
begin
  declare @conversation_handle uniqueidentifier
  declare cur CURSOR for
  SELECT TOP (1000) conversation_handle
  FROM sys.conversation_endpoints
  WHERE NOT EXISTS (SELECT *
  FROM [tcp://AWT/Sonar/Q_ObjectDelete] a
  WHERE a.conversation_handle = sys.conversation_endpoints.conversation_handle)
  AND sys.conversation_endpoints.far_service = tcp://AWT/Sonar/Svc_ObjectDelete
  AND sys.conversation_endpoints.state <> CD
  open cur
  fetch next from cur into @conversation_handle
  while @@fetch_status = 0
  begin
  end conversation @conversation_handle with cleanup
  fetch next from cur into @conversation_handle
  end
  close cur
  deallocate curset @i = @i + 1
endI run this every hour to clean up the bogus records in the sys.conversation_endpoints DMV.
  如果不清理sys.conversation_endpoints DMV,tempdb会慢慢被填满,并在sp_spaceused显示tempdb为空时抛出空间耗尽消息。这跟我之前在另一篇文章所说的一样。


« 
» 
快速导航

Copyright © 2016 phpStudy | 豫ICP备2021030365号-3