I have Service Broker queue infrastructure that I am using in my database for a few months. I realized that my Initiator
queue has reached to 2 million records which are EndDialog
messages. So I re-designed it thanks to this link.
My problem is that I couldn't delete those 2 million records. I used the approach below as indicated in this link, and left the query executing. It executed for 20 hours until I canceled it.
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.
drop service initiatorService
drop queue initiatorQueue
Is there another way to delete immediately?
There is no shortcut to achieve your goal that I know of, unless you are willing to:
ALTER DATABASE ... SET NEW_BROKER WITH ROLLBACK IMMEDIATE;
)Regarding your code, however, I would suggest using receive
instead of 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.