admin 管理员组

文章数量: 1184232

如果你的数据库启用了Service Broker后发现TempDB的size一直在增加,此时可以考虑是否在call service的时候没有结束conversation。

具体怎么结束conversation可以参考另一篇。SQL Server Service Broker启用详解以及常见问题

此文章主要用于清理遗留的conversation去释放TempDB的空间。

脚本如下:

'AuditTrailService'--改成你自己的service名称(可以在你的DB -> Service Broker -> Services )

--End conversation for AuditTrailSyncQueue
declare @ServiceBroker_ServiceName nvarchar(255)='AuditTrailService'--改成你自己的service名称(可以在你的DB -> Service Broker -> Services )
DECLARE @conversationHandle UNIQUEIDENTIFIER;

WHILE (1 = 1)
BEGIN
select TOP 1 @conversationHandle= ce.conversation_handle
from 
sys.conversation_endpoints ce 
left join sys.services ss on ce.service_id=ss.service_id
where state_desc='CONVERSING' and ce.far_service=@ServiceBroker_ServiceName

IF (@@ROWCOUNT = 0)
BREAK;

END CONVERSATION @conversationHandle WITH CLEANUP;
END;

本文标签: 清空 空间 Service SQL Server