Skip to content

Latest commit

 

History

History
117 lines (77 loc) · 8.68 KB

perform-a-planned-manual-failover-of-an-availability-group-sql-server.md

File metadata and controls

117 lines (77 loc) · 8.68 KB
title description author ms.author ms.date ms.service ms.subservice ms.topic f1_keywords helpviewer_keywords
Perform a planned manual failover of an availability group
This topic describes how to perform a planned manual failover of an Always On availability group.
MashaMSFT
mathoma
10/25/2017
sql
availability-groups
conceptual
sql13.swb.availabilitygroup.manualfailover.f1
Availability Groups [SQL Server], failover
failover [SQL Server], AlwaysOn Availability Groups
failover [SQL Server], Always On Availability Groups

Perform a planned manual failover of an Always On availability group (SQL Server)

[!INCLUDE SQL Server] This topic describes how to perform a manual failover without data loss (a planned manual failover) on an Always On availability group by using [!INCLUDEssManStudioFull], [!INCLUDEtsql], or PowerShell in [!INCLUDEssnoversion]. An availability group fails over at the level of an availability replica. A planned manual failover, like any Always On availability group failover, transitions a secondary replica to primary role. Concurrently, the failover transitions the former primary replica to the secondary role.

A planned manual failover is supported only when the primary replica and the target secondary replica are running in synchronous-commit mode and are currently synchronized. A planned manual failover preserves all the data in the secondary databases that are joined to the availability group on the target secondary replica. After the former primary replica transitions to the secondary role, its databases become secondary databases. Then they begin to synchronize with the new primary databases. After they all transition into the SYNCHRONIZED state, the new secondary replica becomes eligible to serve as the target of a future planned manual failover.

Note

If the secondary and primary replicas are both configured for automatic failover mode, after the secondary replica is synchronized, it also can serve as the target for an automatic failover. For more information, see Availability modes (Always On availability groups).

Before you begin

Important

There are specific procedures to fail over a read-scale availability group with no cluster manager. When an availability group has CLUSTER_TYPE = NONE, follow the procedures under Fail over the primary replica on a read-scale availability group.

Limitations and restrictions

Prerequisites and restrictions

  • Both the target secondary replica and the primary replica must be running in synchronous-commit availability mode.

  • Currently, the target secondary replica must be synchronized with the primary replica. All the secondary databases on this secondary replica must be joined to the availability group. They also must be synchronized with their corresponding primary databases (that is, the local secondary databases must be SYNCHRONIZED).

    [!TIP] To determine the failover readiness of a secondary replica, query the is_failover_ready column in the sys.dm_hadr_database_replica_cluster_states dynamic management view. Or you can look at the Failover Readiness column of the Always On group dashboard.

  • This task is supported only on the target secondary replica. You must be connected to the server instance that hosts the target secondary replica.

Security

Permissions

The ALTER AVAILABILITY GROUP permission is required on the availability group. The CONTROL AVAILABILITY GROUP permission, the ALTER ANY AVAILABILITY GROUP permission, or the CONTROL SERVER permission also is required.

Use SQL Server Management Studio

To manually fail over an availability group:

  1. In Object Explorer, connect to a server instance that hosts a secondary replica of the availability group that needs to be failed over. Expand the server tree.

  2. Expand the Always On High Availability node and the Availability Groups node.

  3. Right-click the availability group to be failed over, and select Failover.

  4. The Failover Availability Group wizard starts. For more information, see Use the Failover Availability Group wizard (SQL Server Management Studio).

Use Transact-SQL

To manually fail over an availability group:

  1. Connect to the server instance that hosts the target secondary replica.

  2. Use the ALTER AVAILABILITY GROUP statement, as follows:

    ALTER AVAILABILITY GROUP group_name FAILOVER

    In the statement, group_name is the name of the availability group.

    The following example manually fails over the MyAg availability group to the connected secondary replica:

    ALTER AVAILABILITY GROUP MyAg FAILOVER;  
    

Use PowerShell

To manually fail over an availability group:

  1. Change the directory (cd) to the server instance that hosts the target secondary replica.

  2. Use the Switch-SqlAvailabilityGroup cmdlet.

    [!NOTE] To view the syntax of a cmdlet, use the Get-Help cmdlet in the [!INCLUDEssnoversion] PowerShell environment. For more information, see Get help for SQL Server PowerShell.

    The following example manually fails over the MyAg availability group to the secondary replica with the specified path:

    Switch-SqlAvailabilityGroup -Path SQLSERVER:\Sql\SecondaryServer\InstanceName\AvailabilityGroups\MyAg  
    

    To set up and use the SQL Server PowerShell provider:

Follow up: After you manually fail over an availability group

If you failed over outside the [!INCLUDEssFosAuto] of the availability group, adjust the quorum votes of the Windows Server failover clustering nodes to reflect your new availability group configuration. For more information, see Windows Server failover clustering (WSFC) with SQL Server.

Fail over the primary replica on a read-scale availability group

[!INCLUDEForce failover]

See also