我希望能夠檢查SQL Server 2008 T-SQL中發佈和訂閱的狀態。我希望能夠確定它是否可以,最後一次成功的時間,同步等。這可能嗎?如何通過T-SQL檢查SQL複製狀態?
13
A
回答
27
我知道這是有點晚了....
SELECT
(CASE
WHEN mdh.runstatus = '1' THEN 'Start - '+cast(mdh.runstatus as varchar)
WHEN mdh.runstatus = '2' THEN 'Succeed - '+cast(mdh.runstatus as varchar)
WHEN mdh.runstatus = '3' THEN 'InProgress - '+cast(mdh.runstatus as varchar)
WHEN mdh.runstatus = '4' THEN 'Idle - '+cast(mdh.runstatus as varchar)
WHEN mdh.runstatus = '5' THEN 'Retry - '+cast(mdh.runstatus as varchar)
WHEN mdh.runstatus = '6' THEN 'Fail - '+cast(mdh.runstatus as varchar)
ELSE CAST(mdh.runstatus AS VARCHAR)
END) [Run Status],
mda.subscriber_db [Subscriber DB],
mda.publication [PUB Name],
right(left(mda.name,LEN(mda.name)-(len(mda.id)+1)), LEN(left(mda.name,LEN(mda.name)-(len(mda.id)+1)))-(10+len(mda.publisher_db)+(case when mda.publisher_db='ALL' then 1 else LEN(mda.publication)+2 end))) [SUBSCRIBER],
CONVERT(VARCHAR(25),mdh.[time]) [LastSynchronized],
und.UndelivCmdsInDistDB [UndistCom],
mdh.comments [Comments],
'select * from distribution.dbo.msrepl_errors (nolock) where id = ' + CAST(mdh.error_id AS VARCHAR(8)) [Query More Info],
mdh.xact_seqno [SEQ_NO],
(CASE
WHEN mda.subscription_type = '0' THEN 'Push'
WHEN mda.subscription_type = '1' THEN 'Pull'
WHEN mda.subscription_type = '2' THEN 'Anonymous'
ELSE CAST(mda.subscription_type AS VARCHAR)
END) [SUB Type],
mda.publisher_db+' - '+CAST(mda.publisher_database_id as varchar) [Publisher DB],
mda.name [Pub - DB - Publication - SUB - AgentID]
FROM distribution.dbo.MSdistribution_agents mda
LEFT JOIN distribution.dbo.MSdistribution_history mdh ON mdh.agent_id = mda.id
JOIN
(SELECT s.agent_id, MaxAgentValue.[time], SUM(CASE WHEN xact_seqno > MaxAgentValue.maxseq THEN 1 ELSE 0 END) AS UndelivCmdsInDistDB
FROM distribution.dbo.MSrepl_commands t (NOLOCK)
JOIN distribution.dbo.MSsubscriptions AS s (NOLOCK) ON (t.article_id = s.article_id AND t.publisher_database_id=s.publisher_database_id)
JOIN
(SELECT hist.agent_id, MAX(hist.[time]) AS [time], h.maxseq
FROM distribution.dbo.MSdistribution_history hist (NOLOCK)
JOIN (SELECT agent_id,ISNULL(MAX(xact_seqno),0x0) AS maxseq
FROM distribution.dbo.MSdistribution_history (NOLOCK)
GROUP BY agent_id) AS h
ON (hist.agent_id=h.agent_id AND h.maxseq=hist.xact_seqno)
GROUP BY hist.agent_id, h.maxseq
) AS MaxAgentValue
ON MaxAgentValue.agent_id = s.agent_id
GROUP BY s.agent_id, MaxAgentValue.[time]
) und
ON mda.id = und.agent_id AND und.[time] = mdh.[time]
where mda.subscriber_db<>'virtual' -- created when your publication has the immediate_sync property set to true. This property dictates whether snapshot is available all the time for new subscriptions to be initialized. This affects the cleanup behavior of transactional replication. If this property is set to true, the transactions will be retained for max retention period instead of it getting cleaned up as soon as all the subscriptions got the change.
--and mdh.runstatus='6' --Fail
--and mdh.runstatus<>'2' --Succeed
order by mdh.[time]
2
要檢查出版物或訂閱狀態,你可以使用簡單的工具SQL Server Replication Explorer
4
老的文章,但增加了對其他 - 下面的存儲過程將給你你需要的東西:
- sp_replmonitorhelppublication(https://msdn.microsoft.com/en-us/library/ms186304.aspx)
它允許您查看狀態以及其他信息全部複製出版物的分銷商(分發數據庫上運行它)
相關問題
- 1. 如何檢查/通過設置狀態
- 2. 檢查postgres複製狀態
- 3. 如何複製手動(未)檢查複選框的狀態?
- 4. 檢查Mysql複製的狀態
- 5. SQL Server FTI:如何檢查表狀態?
- 6. 通過Shellscript檢查Teamspeak狀態(Ubuntu)
- 7. 通過DATABASE_URL檢查數據庫狀態
- 8. python:通過ID檢查線程狀態
- 9. TSQL查找複製
- 10. 如何通過代碼獲取狀態mysql複製
- 11. 如何:通過C#獲取合併複製狀態
- 12. 如何通過SQL服務器遠程檢查應用程序池狀態
- 13. 如何通過終端檢查TRIM狀態
- 14. 如何通過3G連接檢查互聯網連接狀態?
- 15. 如何預防的OutOfMemoryError通過檢查堆狀態
- 16. 如何通過PHP檢查JavaScript是否處於活動狀態?
- 17. 如何檢查狀態onKeypress
- 18. 如何檢查namenode狀態?
- 19. 如何檢查JDialog狀態
- 20. 如何通過spark-sql複製表格
- 21. sql - 在sql中雙重檢查狀態
- 22. 如何檢查動態創建的複選框狀態
- 23. 如何動態地更改複選框檢查狀態
- 24. 檢查在線狀態,例如通過pinging
- 25. 如何通過LINQ或TSQL
- 26. 如何通過jQuery檢查值檢查複選框屬性值?
- 27. 如何將檢查狀態設置爲false如果檢查狀態不確定
- 28. SQL複製返回否狀態
- 29. Android如何保存3種不同檢查狀態的複選框狀態
- 30. 鏡像複選框已檢查狀態
這是有一個夢幻般的查詢! – 2015-11-19 14:25:28