Tsql - 获取alwayson可用性组

时间:2016-05-04 12:17:50

标签: sql-server tsql alwayson

我想连接到AlwaysOn可用性组中的侦听器,通过运行查询,我将获得属于AlwaysOn的实例列表。 例如: 我有听众" MylistenerHost"并且有2个实例连接到他:SqlHost1(primary-readwrite)和SqlHost2(secondary - readonly)。

我需要一个我将运行的查询,他将向我展示这些实例化,SqlHost1和SqlHost2,并且SqlHost1是主要的,SqlHost2是次要的。

10X

1 个答案:

答案 0 :(得分:2)

您可以在主副本上执行这样的查询。

SELECT C.name, CS.replica_server_name, CS.join_state_desc, RS.role_desc, RS.operational_state_desc, RS.connected_state_desc, RS.synchronization_health_desc
    FROM sys.availability_groups_cluster AS C
        INNER JOIN sys.dm_hadr_availability_replica_cluster_states AS CS
            ON CS.group_id = C.group_id
        INNER JOIN sys.dm_hadr_availability_replica_states AS RS
            ON RS.replica_id = CS.replica_id;

enter image description here

请参阅联机丛书>监视可用性组(Transact-SQL):https://msdn.microsoft.com/en-us/library/ff878305.aspx#AGlisteners