使用 AlwaysOn 原則檢視可用性群組的健全狀況 (SQL Server)Use Always On Policies to View the Health of an Availability Group (SQL Server)

適用範圍:Applies to: 是SQL ServerSQL Server (所有支援的版本) yesSQL ServerSQL Server (all supported versions) 適用範圍:Applies to: 是SQL ServerSQL Server (所有支援的版本) yesSQL ServerSQL Server (all supported versions)

此主題描述如何使用 SQL Server Management StudioSQL Server Management Studio 中的 AlwaysOn 原則或 SQL ServerSQL Server中的 PowerShell,判斷 AlwaysOn 可用性群組的作業健全狀況。This topic describes how to determine the operational health of an Always On availability group by using an Always On policy in SQL Server Management StudioSQL Server Management Studio or PowerShell in SQL ServerSQL Server. 如需 AlwaysOn 原則式管理的詳細資訊,請參閱 AlwaysOn 可用性群組操作問題適用的 AlwaysOn 原則 (SQL Server)中的 PowerShell,判斷 AlwaysOn 可用性群組的作業健全狀況。For information about Always On Policy Based Management, see Always On Policies for Operational Issues with Always On Availability Groups (SQL Server).

重要

對於 AlwaysOn 原則而言,類別目錄名稱會當作識別碼使用。For Always On policies, the category names are used as IDs. 變更 AlwaysOn 類別目錄的名稱會破壞其健全狀況評估功能。Changing the name of an Always On category would break its health-evaluation functionality. 因此,永遠不應修改 AlwaysOn 類別目錄的名稱。Therefore, the names of Always On category should never be modified.

權限Permissions

需要 CONNECT、VIEW SERVER STATE 和 VIEW ANY DEFINITION 權限。Requires CONNECT, VIEW SERVER STATE, and VIEW ANY DEFINITION permissions.

使用 AlwaysOn 儀表板Using the Always On Dashboard

開啟 AlwaysOn 儀表板To open the Always On Dashboard

  1. 在 [物件總管] 中,連接到裝載其中一個可用性複本的伺服器執行個體。In Object Explorer, connect to the server instance that hosts one of the availability replicas. 若要檢視可用性群組中所有可用性複本的相關資訊,請用於裝載主要複本的伺服器執行個體。To view information about all of the availability replicas in an availability group, use to the server instance that hosts the primary replica.

  2. 按一下伺服器名稱展開伺服器樹狀目錄。Click the server name to expand the server tree.

  3. 展開 [AlwaysOn 高可用性] 節點。Expand the Always On High Availability node.

    以滑鼠右鍵按一下 [可用性群組] 節點,或展開此節點,然後以滑鼠右鍵按一下特定的可用性群組。Either right-click the Availability Groups node or expand this node and right-click a specific availability group.

  4. 選取 [顯示儀表板] 命令。Select the Show Dashboard command.

如需如何使用 AlwaysOn 儀表板的詳細資訊,請參閱使用 AlwaysOn 儀表板 (SQL Server Management Studio)For information about how to use the Always On Dashboard, see Use the Always On Dashboard (SQL Server Management Studio).

使用 PowerShellUsing PowerShell

Use Always On policies to view the health of an availability groupUse Always On policies to view the health of an availability group

  1. 將目錄切換到 (cd) 裝載其中一個可用性複本的伺服器執行個體。Set default (cd) to a server instance that hosts one of the availability replicas. 若要檢視可用性群組中所有可用性複本的相關資訊,請用於裝載主要複本的伺服器執行個體。To view information about all of the availability replicas in an availability group, use to the server instance that hosts the primary replica.

  2. 使用下列 Cmdlet:Use the following cmdlets:

    Test-SqlAvailabilityGroupTest-SqlAvailabilityGroup
    透過評估 SQL Server 原則式管理 (PBM) 原則,評估可用性群組的健全狀況。Assesses the health of an availability group by evaluating SQL Server policy based management (PBM) policies. 您必須擁有 CONNECT、VIEW SERVER STATE 和 VIEW ANY DEFINITION 權限,才能執行這個 Cmdlet。You must have CONNECT, VIEW SERVER STATE, and VIEW ANY DEFINITION permissions to execute this cmdlet.

    例如,下列命令會顯示伺服器執行個體 Computer\Instance上健全狀態為 "Error" 的所有可用性群組。For example, the following command shows all availability groups with a health state of "Error" on the server instance Computer\Instance.

    Get-ChildItem SQLSERVER:\Sql\Computer\Instance\AvailabilityGroups `   
    | Test-SqlAvailabilityGroup | Where-Object { $_.HealthState -eq "Error" }  
    

    Test-SqlAvailabilityReplicaTest-SqlAvailabilityReplica
    透過評估 SQL Server 原則式管理 (PBM) 原則,評估可用性複本的健全狀況。Assesses the health of availability replicas by evaluating SQL Server policy based management (PBM) policies. 您必須擁有 CONNECT、VIEW SERVER STATE 和 VIEW ANY DEFINITION 權限,才能執行這個 Cmdlet。You must have CONNECT, VIEW SERVER STATE, and VIEW ANY DEFINITION permissions to execute this cmdlet.

    例如,下列命令會評估可用性群組 MyReplica 中名為 MyAg 之可用性複本的健全狀況並且輸出簡短摘要。For example, the following command evaluates the health of the availability replica named MyReplica in the availability group MyAg and outputs a brief summary.

    Test-SqlAvailabilityReplica `   
    -Path SQLSERVER:\Sql\Computer\Instance\AvailabilityGroups\MyAg\AvailabilityReplicas\MyReplica  
    

    Test-SqlDatabaseReplicaStateTest-SqlDatabaseReplicaState
    透過評估 SQL Server 原則式管理 (PBM) 原則,評估所有聯結可用性複本之可用性資料庫的健全狀況。Assesses the health of an availability database on all joined availability replicas by evaluating SQL Server policy based management (PBM) policies.

    例如,下列命令會評估可用性群組 MyAg 中所有可用性資料庫的健全狀況並且輸出每個資料庫的簡短摘要。For example, the following command evaluates the health of all availability databases in the availability group MyAg and outputs a brief summary for each database.

    Get-ChildItem SQLSERVER:\Sql\Computer\Instance\AvailabilityGroups\MyAg\DatabaseReplicaStates `   
     | Test-SqlDatabaseReplicaState  
    

    這些指令程式接受下列選項:These cmdlets accept the following options:

    選項Option 描述Description
    AllowUserPoliciesAllowUserPolicies 執行 AlwaysOn 原則類別目錄中的使用者原則。Runs user policies found in the Always On policy categories.
    InputObjectInputObject 表示可用性群組、可用性複本或可用性資料庫狀態的物件集合 (依據使用的指令程式而定)。A collection of objects that, represent availability groups, availability replicas, or availability database states (depending on which cmdlet you are using). 指令程式會計算指定之物件的健全狀況。The cmdlet will compute the health of the specified objects.
    NoRefreshNoRefresh 設定此參數時,Cmdlet 不會手動重新整理 -Path-InputObject 參數所指定的物件。When this parameter is set, the cmdlet will not manually refresh the objects specified by the -Path or -InputObject parameter.
    路徑Path 可用性群組、一個或多個可用性複本,或可用性資料庫之資料庫複本叢集狀態的路徑 (依據使用的指令程式而定)。The path to the availability group, one or more availability replicas, or database replica cluster state of the availability database (depending on which cmdlet you are using). 這是選擇性參數。This is an optional parameter. 如果未指定,此參數的值預設為目前的工作位置。If not specified, the value of this parameter defaults to the current working location.
    ShowPolicyDetailsShowPolicyDetails 顯示此 Cmdlet 執行之各項原則評估的結果。Shows the result of each policy evaluation performed by this cmdlet. Cmdlet 針對每項原則評估輸出一個物件,此物件的欄位描述評估結果 (原則通過或失敗、原則名稱和類別目錄等等)。The cmdlet outputs one object per policy evaluation, and this object has fields describing the results of evaluation (whether the policy passed or not, the policy name and category, and so forth).

    例如,下列 Test-SqlAvailabilityGroup 命令會指定 -ShowPolicyDetails 參數,針對在可用性群組 MyAg上執行的每個原則式管理 (PBM) 原則,顯示此 Cmdlet 執行的每個原則評估結果。For example, the following Test-SqlAvailabilityGroup command specifies the -ShowPolicyDetails parameter to show the result of each policy evaluation performed by this cmdlet for each policy-based management (PBM) policy that was executed on the availability group named MyAg.

    Test-SqlAvailabilityGroup `   
    -Path SQLSERVER:\Sql\Computer\Instance\AvailabilityGroups\AgName `  
    -ShowPolicyDetails  
    
    

    注意

    若要檢視 Cmdlet 的語法,請在 PowerShell 環境中使用 Get-Help SQL ServerSQL Server Cmdlet。To view the syntax of a cmdlet, use the Get-Help cmdlet in the SQL ServerSQL Server PowerShell environment. 如需詳細資訊,請參閱 Get Help SQL Server PowerShellFor more information, see Get Help SQL Server PowerShell.

若要設定和使用 SQL Server PowerShell 提供者To set up and use the SQL Server PowerShell provider

SQL Server AlwaysOn 團隊部落格 - 使用 PowerShell 監視 AlwaysOn 健全狀況:SQL Server Always On Team Blogs-Monitoring Always On Health with PowerShell:

另請參閱See Also

AlwaysOn 可用性群組概觀 (SQL Server) Overview of Always On Availability Groups (SQL Server)
可用性群組的管理 (SQL Server) Administration of an Availability Group (SQL Server)
監視可用性群組 (SQL Server) Monitoring of Availability Groups (SQL Server)
AlwaysOn 可用性群組操作問題適用的 AlwaysOn 原則 (SQL Server)Always On Policies for Operational Issues with Always On Availability Groups (SQL Server)