简体   繁体   English

SQL 服务器 Service Broker - 删除服务

[英]SQL Server Service Broker - Drop service

I have Service Broker queue infrastructure that I am using in my database for a few months.我有几个月来一直在我的数据库中使用的 Service Broker 队列基础结构。 I realized that my Initiator queue has reached to 2 million records which are EndDialog messages.我意识到我的Initiator队列已达到 200 万条记录,这些记录是EndDialog消息。 So I re-designed it thanks to this link .所以我通过这个链接重新设计了它。

My problem is that I couldn't delete those 2 million records.我的问题是我无法删除那 200 万条记录。 I used the approach below as indicated in this link , and left the query executing.我使用了此链接中所示的以下方法,并让查询继续执行。 It executed for 20 hours until I canceled it.它执行了 20 个小时,直到我取消它。

declare @c uniqueidentifier
while(1=1)
begin
    select top 1 @c = conversation_handle from dbo.queuename
    if (@@ROWCOUNT = 0)
    break
    end conversation @c with cleanup
end

Now I am trying to drop Service and Queue but it seems it is gonna take lots of time again.现在我正在尝试删除 Service 和 Queue,但它似乎又会花费很多时间。

drop service initiatorService
drop queue initiatorQueue

Is there another way to delete immediately?还有其他方法可以立即删除吗?

Queue Data;队列数据; 在此处输入图像描述

There is no shortcut to achieve your goal that I know of, unless you are willing to: 除非您愿意,否则没有捷径可以实现您所知道的目标。

  • Drop and recreate the database, or 删除并重新创建数据库,或者
  • Reset all Service Broker data in all queues, including dialogs themselves, in that database (in this case, you might try to follow Remus' advise in the linked question - ALTER DATABASE ... SET NEW_BROKER WITH ROLLBACK IMMEDIATE; ) 重置该数据库中所有队列(包括对话框本身)中的所有Service Broker数据(在这种情况下,您可以尝试按照链接问题ALTER DATABASE ... SET NEW_BROKER WITH ROLLBACK IMMEDIATE;中的Remus的建议进行操作)

Regarding your code, however, I would suggest using receive instead of select ; 至于您的代码,我建议您使用receive而不是select ; otherwise you might get the same dialog multiple times. 否则,您可能会多次获得相同的对话框。 Also, you might want to distinguish EndDialog messages from any others if they occur in the queue. 另外,如果EndDialog消息出现在队列中,您可能希望将它们与其他消息区分开。

I had a similar issue where removing the services took really long.我有一个类似的问题,删除服务花了很长时间。 So long my SQL server ran out of memory and crashed.这么久我的 SQL 服务器用完了 memory 并崩溃了。 I first tried ending the dialog with the query you posted at the top, but that didn't help.我首先尝试用您在顶部发布的查询结束对话,但这没有帮助。 In my case there were a lot of conversations created that were never closed.在我的例子中,创建了很多从未关闭的对话。 So although the queues were empty, there were still a lot conversations when I queryed sys.conversation_endpoints.所以虽然队列是空的,但是当我查询 sys.conversation_endpoints 时仍然有很多对话。 I used the following script to clean up the conversations and after that I was able to delete it instantly.我使用以下脚本来清理对话,然后我能够立即将其删除。

Note that below query will close all conversations, no matter the queue so you need to filter if you only want to delete a specific one请注意,下面的查询将关闭所有对话,无论队列如何,因此如果您只想删除特定的对话,则需要进行过滤

declare @c uniqueidentifier
while(1=1)
begin
    select top 1 @c = conversation_handle from sys.conversation_endpoints
    if (@@ROWCOUNT = 0)
    break
    end conversation @c with cleanup
end

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM