Create or Configure an Availability Group Listener (SQL Server)
This topic describes how to create or configure a single availability group listener for an AlwaysOn availability group by using SQL Server Management Studio, Transact-SQL, or PowerShell in SQL Server 2012.
Important
|
|---|
|
To create the first availability group listener of an availability group, we strongly recommend that you SQL Server Management Studio, Transact-SQL, or SQL Server PowerShell. Avoid creating a listener directly in the WSFC cluster except when necessary, for example, to create an additional listener. |
-
Before you begin:
Does a Listener Exist for this Availability Group Already?
Requirements for the DNS Name of an Availability Group Listener
-
To create or configure an availability group listener, using:
-
Follow up:
After Creating an Availability Group Listener
To Create An Additional Listener for an Availability Group (Optional)
Does a Listener Exist for this Availability Group Already?
To determine whether a listener already exists for the availability group
Note
|
|---|
|
If a listener already exists and you want to create an additional listener, see To Create An Additional Listener for an Availability Group (Optional), later in this topic. |
Limitations and Restrictions
-
You can create only one listener per availability group through SQL Server. Typically, each availability group requires only one listener. However, some customer scenarios require multiple listeners for one availability group. After creating a listener through SQL Server, you can use Windows PowerShell for failover clusters or the WSFC Failover Cluster Manager to create additional listeners. For more information, see To Create An Additional Listener for an Availability Group (Optional), later in this topic.
Recommendations
Using a static IP address is recommended, although not required, for multiple subnet configurations.
Prerequisites
-
You must be connected to the server instance that hosts the primary replica.
-
If you are setting up an availability group listener across multiple subnets and plan to use static IP addresses, you need to get the static IP address of every subnet that hosts an availability replica for the availability group for which you are creating the listener. Usually, you will need to ask your network administrators for the static IP addresses.
Important
|
|---|
|
Before you create your first listener, we strongly recommend that you read Prerequisites, Restrictions, and Recommendations for AlwaysOn Client Connectivity (SQL Server). |
Requirements for the DNS Name of an Availability Group Listener
Each availability group listener requires a DNS host name that is unique in the domain and in NetBIOS. The DNS name is a string value. This name can contain only alphanumeric characters, dashes (-), and hyphens (_), in any order. DNS host names are case insensitive. The maximum length is 63 characters, however, in SQL Server Management Studio, the maximum length you can specify is 15 characters.
We recommend that you specify a meaningful string. For example, for an availability group named AG1, a meaningful DNS host name would be ag1-listener.
Important
|
|---|
|
NetBIOS recognizes only the first 15 chars in the dns_name. If you have two WSFC clusters that are controlled by the same Active Directory and you try to create availability group listeners in both of clusters using names with more than 15 characters and an identical 15 character prefix, you will get an error reporting that the Virtual Network Name resource could not be brought online. For information about prefix naming rules for DNS names, see Assigning Domain Names. |
Windows Permissions
|
Permissions |
Link |
||
|---|---|---|---|
|
The cluster object name (CNO) of WSFC cluster that is hosting the availability group must have Create Computer objects permission:
|
|
||
|
If your organization requires that you prestage the computer account for a listener virtual network name, you will need membership in the Account Operator group or your domain administrator's assistance.
|
Steps for prestaging an account for a clustered service or application in Failover Cluster Step-by-Step Guide: Configuring Accounts in Active Directory. |
SQL Server Permissions
|
Task |
Permissions |
|---|---|
|
To create an availability group listener |
Requires membership in the sysadmin fixed server role and either CREATE AVAILABILITY GROUP server permission, ALTER ANY AVAILABILITY GROUP permission, or CONTROL SERVER permission. |
|
To modify an existing availability group listener |
Requires ALTER AVAILABILITY GROUP permission on the availability group, CONTROL AVAILABILITY GROUP permission, ALTER ANY AVAILABILITY GROUP permission, or CONTROL SERVER permission. |
Tip
|
|---|
|
The New Availability Group wizard supports creation of the listener for a new availability group. |
To create or configure an availability group listener
-
In Object Explorer, connect to the server instance that hosts the primary replica of the availability group, and click the server name to expand the server tree.
-
Expand the AlwaysOn High Availability node and the Availability Groups node.
-
Click the availability group whose listener you want to configure, and choose one of the following alternatives:
-
To create a listener, right-click the Availability group Listeners node, and select the New Listener command. This opens the New Availability Group Listener dialog box. For more information, see Add Availability Group Listener (Dialog Box), later in this topic.
-
To change the port number of an existing listener, expand the Availability group Listeners node, right-click the listener, and select the Properties command. Enter the new port number into the Port field, and click OK.
-
New Availability Group Listener (Dialog Box)
To create or configure an availability group listener
-
Connect to the server instance that hosts the primary replica.
-
Use the LISTENER option of the CREATE AVAILABILITY GROUP statement or the ADD LISTENER option of the ALTER AVAILABILITY GROUP statement.
The following example adds an availability group listener to an existing availability group named MyAg2. A unique DNS name, MyAg2ListenerIvP6, is specified for this listener. The two replicas are on different subnets, so , as recommended, the listener uses static IP addresses. For each of the two availability replicas, the WITH IP clause specifies a static IP address, 2001:4898:f0:f00f::cf3c and 2001:4898:e0:f213::4ce2, which use the IPv6 format. This example also specifies uses the optional PORT argument to specify port 60173 as the listener port.
ALTER AVAILABILITY GROUP MyAg2 ADD LISTENER ‘MyAg2ListenerIvP6’ ( WITH IP ( ('2001:db88:f0:f00f::cf3c'),('2001:4898:e0:f213::4ce2') ) , PORT = 60173 ); GO
To create or configure an availability group listener
-
Change directory (cd) to the server instance that hosts the primary replica.
-
To create or modify an availability group listener use one of the following cmdlets:
Note
To view the syntax of a cmdlet, use the Get-Help cmdlet in the SQL Server PowerShell environment. For more information, see Get Help SQL Server PowerShell.
To set up and use the SQL Server PowerShell provider
RegisterAllProvidersIP Setting
When you use SQL Server Management Studio, Transact-SQL, or PowerShell to create an availability group listener, the Client Access Point is created in WSFC with the RegisterAllProvidersIP property set to 1 (true). The effect of this property value depends on the client connection string, as follows:
-
Connection strings that set MultiSubnetFailover to true
AlwaysOn Availability Groups sets the RegisterAllProvidersIP property to 1 in order to reduce re-connection time after a failover for clients whose client connection strings specify MultiSubnetFailover = yes (or true), as recommended. Note that to take advantage of the listener multi-subnet feature, your clients might require a data provider that supports the MultiSubnetFailover keyword. For information about driver support for multi-subnet failover, see "5.7.1 Client-Connectivity for AlwaysOn Availability Groups" in the SQL Server 2012 Release Notes.
For information about multi-subnet clustering, see SQL Server Multi-Subnet Clustering (SQL Server).
Tip
When RegisterAllProvidersIP = 1, if you run the WSFC Validate a Configuration Wizard on the WSFC cluster, the wizard generates the following warning message:
"The RegisterAllProviderIP property for network name 'Name:<network_name>' is set to 1 For the current cluster configuration this value should be set to 0."
Please ignore this message.
-
Connection strings that do not set MultiSubnetFailover to true
When RegisterAllProvidersIP = 1, any clients whose connection strings do not use MultiSubnetFailover = yes (or true), will experience high latency connections. This occurs because these clients attempt connections to all IPs sequentially. In contrast, if RegisterAllProvidersIP is changed to 0, the active IP address is listed in the Client Access Point in the WSFC cluster, reducing latency for legacy clients.
Therefore, if you have legacy clients that that need to connect to an availability group listener and cannot use the MultiSubnetFailover property, we recommend that you change RegisterAllProvidersIP to 0. The following PowerShell example demonstrates how to do this. Replace yourListenerName with the name of the listener that you are changing.
Import-Module FailoverClusters Get-ClusterResource yourListenerName|Set-ClusterParameter RegisterAllProvidersIP 0
For information about available options and workarounds, see "5.7.1 Client-Connectivity for AlwaysOn Availability Groups" in the SQL Server 2012 Release Notes and Client Recovery Latency During Failover.
Follow Up Recommendations
After you create an availability group listener:
-
Ask your network administrator to reserve the listener's IP address for its exclusive use.
-
Give the listener's DNS host name to application developers to use in connection strings when requesting client connections to this availability group.
-
Encourage developers to update client connection strings to specify MultiSubnetFailover = yes (or true), if possible. For information about driver support for multi-subnet failover, see "5.7.1 Client-Connectivity for AlwaysOn Availability Groups" in the SQL Server 2012 Release Notes.
To Create An Additional Listener for an Availability Group (Optional)
After you create one listener through SQL Server, you can add an additional listener, as follows:
-
Create the listener using either of the following tools:
-
Using WSFC Failover Cluster Manager:
-
Add a client access point and configure the IP address.
-
Bring the listener online.
-
Add a dependency to the WSFC availability group resource.
For information about the dialog boxes and tabs of the Failover Cluster Manager, see User Interface: The Failover Cluster Manager Snap-In.
-
-
Using Windows PowerShell for failover clusters:
-
Use Add-ClusterResource to create a network name and the IP address resources.
-
Use Start-ClusterResource to start the network name resource.
-
Use Add-ClusterResourceDependency to set the dependency between the network name and the existing SQL Server Availability Group resource.
For information about using Windows PowerShell for failover clusters, see Overview of Server Manager Commands.
-
-
-
Start SQL Server listening on the new listener. After creating the additional listener, connect to the instance of SQL Server that hosts the primary replica of the availability group and use SQL Server Management Studio, Transact-SQL, or PowerShell to modify the listener port.
Important
|
|---|
|
When you create an availability group listener through the WSFC cluster (Failover Cluster Manager GUI), RegisterAllProvidersIP will be 0 (false) by default. When RegisterAllProvidersIP is 0, only the active IP address is registered. This will increase re-connection time after a failover. To avoid this, change RegisterAllProvidersIP to 1 for the listener, and use MultiSubnetFailover = yes (or true) in your application connection string. The following PowerShell example demonstrates how to change RegisterAllProvidersIP to 1 for the listener. Replace yourListenerName with the name of the listener that you are changing. Import-Module FailoverClusters Get-ClusterResource yourListenerName|Set-ClusterParameter RegisterAllProvidersIP 1 |
For more information, see How to create multiple listeners for same availability group (a SQL Server AlwaysOn team blog).

Important