小编给大家分享一下数据库中AGStatus SQL的示例代码,相信大部分人都还不怎么了解,因此分享这篇文章给大家参考一下,希望大家阅读完这篇文章后大有收获,下面让我们一起去了解一下吧!
select n.group_name,
n.node_name,
CASE WHEN rs.is_local = 1 THEN N'LOCAL' ELSE 'REMOTE' END as is_local,
rs.connected_state_desc,
CASE WHEN drs.suspend_reason_desc='SUSPEND_FROM_USER' THEN '用户手动挂起数据移动'
WHEN drs.suspend_reason_desc='SUSPEND_FROM_REDO' THEN '在重做阶段中出错'
WHEN drs.suspend_reason_desc='SUSPEND_FROM_CAPTURE' THEN '在捕获主副本上的日志时出错'
WHEN drs.suspend_reason_desc='SUSPEND_FROM_UNDO' THEN '在撤消阶段中出错(请参阅错误日志)'
WHEN drs.suspend_reason_desc='SUSPEND_FROM_XRF_UPDATE' THEN '找不到公共日志点(请参阅错误日志)'
END as is_suspended, --是否数据库挂起及原因
drs.synchronization_health_desc,
ISNULL(drs.redo_queue_size,0) as redo_queue_size, --辅助副本的日志文件中尚未重做的日志记录量 (KB)
ELSE CAST(ISNULL(drs.log_send_queue_size,0)*1./ISNULL(drs.log_send_rate,0) AS DECIMAL(18,2))
CASE WHEN ISNULL(drs.redo_rate,0)=0 THEN 0
END as redo_need_time --辅助副本中日志记录重做完成需要时间(秒)
join sys.dm_hadr_availability_replica_cluster_states cs
join sys.dm_hadr_availability_replica_states rs
join sys.dm_hadr_database_replica_states drs
where rs.connected_state_desc<>'CONNECTED'
or drs.is_suspended<>0
or CASE WHEN ISNULL(drs.redo_rate,0)=0 THEN 0 ELSE CAST(ISNULL(drs.redo_queue_size,0)*1./ISNULL(drs.redo_rate,0) AS DECIMAL(18,2)) END>100
以上是“数据库中AGStatus SQL的示例代码”这篇文章的所有内容,感谢各位的阅读!相信大家都有了一定的了解,希望分享的内容对大家有所帮助,如果还想学习更多知识,欢迎关注亿速云行业资讯频道!