前向澄清:我在这个问题中使用 RPO 来描述“估计的数据丢失”,并使用 RTO 来描述“估计的恢复时间”。我意识到它们不是确切的定义,但对于这个问题来说已经足够接近了。
在本文的底部,有一段优秀的代码块用于计算给定的 Always-On 启用实例的 RPO:
--@EstimatedDataLoss (RPO)
WITH DR_CTE ( replica_server_name, database_name, last_commit_time)
AS
(
select ar.replica_server_name, database_name, rs.last_commit_time
from master.sys.dm_hadr_database_replica_states rs
inner join master.sys.availability_replicas ar on rs.replica_id = ar.replica_id
inner join sys.dm_hadr_database_replica_cluster_states dcs on dcs.group_database_id = rs.group_database_id and rs.replica_id = dcs.replica_id
where replica_server_name != @@servername
)
select ar.replica_server_name, dcs.database_name, rs.last_commit_time, DR_CTE.last_commit_time 'DR_commit_time', datediff(ss, DR_CTE.last_commit_time, rs.last_commit_time) 'lag_in_seconds'
from master.sys.dm_hadr_database_replica_states rs
inner join master.sys.availability_replicas ar on rs.replica_id = ar.replica_id
inner join sys.dm_hadr_database_replica_cluster_states dcs on dcs.group_database_id = rs.group_database_id and rs.replica_id = dcs.replica_id
inner join DR_CTE on DR_CTE.database_name = dcs.database_name
where ar.replica_server_name = @@servername
order by lag_in_seconds desc
通过我自己的一些修改,可以为 RTO 导出类似的查询:
--@EstimatedRecoveryTime (RTO)
select ar.replica_server_name, dcs.database_name, rs.redo_queue_size, rs.redo_rate, rs.redo_queue_size/rs.redo_rate as TRedo
from master.sys.dm_hadr_database_replica_states rs
inner join master.sys.availability_replicas ar on rs.replica_id = ar.replica_id
inner join sys.dm_hadr_database_replica_cluster_states dcs on dcs.group_database_id = rs.group_database_id and rs.replica_id = dcs.replica_id
where ar.replica_server_name != @@servername
这些指标适用于我的 Always-On 环境,但我希望在某些 2012 年之前的环境中对 SQL 镜像应用相同的指标。
是否有类似的系统对象来计算 SQL 镜像的相同指标?
注意:我对什么算作 RTO 和 RPO 的引用来自这篇 Mircosoft 文章:
https://msdn.microsoft.com/en-us/library/dn135338(v=sql.110).aspx