-
Notifications
You must be signed in to change notification settings - Fork 10
Proc FB_AGFailover
Previous Split Brain Scenarios | Proc FB_AGPostFailover Next |
---|
The FB_AGFailover procedure performs a failover of the following types of availability group, and can be run on either the Primary server or a Secondary server:
- Distributed Availability Group (dAG)
- Use of FB_AGFailover is not yet tested for Classic Availability Group (AG) and Basic Availability Group (bAG) failover
The FB_AGFailover procedure encapsulates all of the processes needed to complete a failover that can be performed within SQL Server.
The following items must be in place in order for FB_AGFailover to be used:
-
Install FB_AGFailover on all servers within the availability group
-
Ensure Linked Server definitions exist for all the servers in the availability group
The linked server name must be the same as the AG or bAG name. For a dAG, the linked server name must be the same as the underlying AG name
All servers in the availability group must have the full set of linked server names, in order to allow failover to or from any of the servers
-
dAG Failovers: DNS Alias exists
A dAG does not have a listener, so routing application connections for a dAG cannot be performed within SQL Server and this process must be performed manually.
It is recommended that a DNS alias is created with the same name as the dAG that points to the current Primary server, with all application connections configured to use the DNS alias name. The DNS alias can then be manually updated to the new primary server after a failover, allowing all applications to connect to the new primary server without any changes being needed to their connection strings.
EXEC master.dbo.FB_AGFailover 'AvailabilityGroupName'
If FB_AGFailover is run on the Primary server, it will fail over to the first Secondary server found when sorting the names of thre secondary servers.
If FB_AGFailover is run on a Secondary server it will fail over to make that secondary server into the Primary server
Do not use any of the other parameters found within FB_AGFailover, they are used to perform the various tasks required for the failover process
-
Gather Data
FB_AGFailover gathers data about the availability group to be failed over, in order to control which processes should be used to perform the failover
A summary of the data gathering results are printed
-
Ensure Primary And Secondary Servers Synchronised
If asynchronous replication is being used, FB_AGFailover will issue the following commands to put the availability group into synchronous replication. FB_AGFailover will then wait until the Primary server reports all databases are synchronised:
ALTER AVAILABILITY GROUP [AvailabilityGroup] MODIFY AVAILABILITY GROUP ON 'PrimaryServer' WITH (AVAILABILITY_MODE=SYNCHRONOUS_COMMIT), 'SecondaryServer' WITH (AVAILABILITY_MODE=SYNCHRONOUS_COMMIT);
-
Reset Server Roles
If a dAG is being failed over, FB_AGFailover will process the following command to reverse the role of the Primary server. FB_AGFailover will then wait until the Secondary server reports all databases are synchronised:
ALTER AVAILABILITY GROUP [AvailabilityGroup] SET (ROLE=SECONDARY);
-
Perform Failover
a. Perform Failover: not dAG
If a normal AG is being failed over, FB_AGFailover will process the following command to perform the failover:
ALTER AVAILABILITY GROUP [AvailabilityGroup] FAILOVER;
b. Perform Failover: dAG only
If a Distributed AG is being failed over, FB_AGFailover will process the following command to perform the failover:
ALTER AVAILABILITY GROUP [AvailabilityGroup] FORCE_FAILOVER_ALLOW_DATA_LOSS;
-
Reset Synchronisation Mode
If the availability group was originally using asynchronous replication, FB_AGFailover will process the following command to re-establish asynchronous replication.
This step is bypassed if the availability group was originally using synchronous replication
ALTER AVAILABILITY GROUP [AvailabilityGroup] MODIFY AVAILABILITY GROUP ON 'PrimaryServer' WITH (AVAILABILITY_MODE=ASYNCHRONOUS_COMMIT), 'SecondaryServer' WITH (AVAILABILITY_MODE=ASYNCHRONOUS_COMMIT);
-
Report Results
A summary of the results of the failover are printed.
If a dAG was failed over, a reminder to update the DNS alias is also printed
Copyright FineBuild Team © 2020. License and Acknowledgements
Previous Split Brain Scenarios | Top | Proc FB_AGPostFailover Next |
---|
Key SQL FineBuild Links:
SQL FineBuild supports:
- All SQL Server versions from SQL 2019 through to SQL 2005
- Clustered, Non-Clustered and Core implementations of server operating systems
- Availability and Distributed Availability Groups
- 64-bit and (where relevant) 32-bit versions of Windows
The following Windows versions are supported:
- Windows 2022
- Windows 11
- Windows 2019
- Windows 2016
- Windows 10
- Windows 2012 R2
- Windows 8.1
- Windows 2012
- Windows 8
- Windows 2008 R2
- Windows 7
- Windows 2008
- Windows Vista
- Windows 2003
- Windows XP