To monitor sql replication, i use following query. This query always give me all subscription results which currently distribution jobs not running currently.
for example, i have 10 subscriptions and 8 subscriptions runs on demand and 2 subscriptions run continuously.
when i run this query i always get only 8 subscriptions results which setup on demand. why?
how can i modify query to get all 10 subscriptions?
SELECT RIGHT(SUBSTRING(mda.name, 1,LEN(mda.name) - CHARINDEX('-', REVERSE(mda.name))),
CHARINDEX('-',
REVERSE(SUBSTRING(mda.name, 1,
LEN(mda.name) - CHARINDEX('-',
REVERSE(mda.name)))))
- 1) [SUBSCRIBER] ,
mda.[name] AS [DistributionAgentName] ,
mdh.[start_time] AS [DistributionAgentStartTime] ,
mdh.[duration] AS [DistributionAgentRunningDurationInSeconds] ,
( 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] ,
CONVERT(VARCHAR(25), mdh.[time]) [LastSynchronized] ,
DATEDIFF(HOUR,mdh.[time],GETDATE()) [LastSynch(Hrs)],
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] ,
( 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] ,
GETDATE() AS [InfoInsertTime]
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 )
RIGHT 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'
ORDER BY mdh.[time]