-
group_name
-
Specifies the name of the new availability group. group_name must be a valid SQL Server identifier, and it must be unique across all availability groups in the WSFC cluster. The maximum length for an availability group name is 128 characters.
-
AUTOMATED_BACKUP_PREFERENCE = { PRIMARY | SECONDARY_ONLY| SECONDARY | NONE }
-
Specifies a preference about how a backup job should evaluate the primary replica when choosing where to perform backups. You can script a given backup job to take the automated backup preference into account. It is important to understand that the preference is not enforced by SQL Server, so it has no impact on ad-hoc backups.
The supported values are as follows:
-
PRIMARY
-
Specifies that the backups should always occur on the primary replica. This option is useful if you need backup features, such as creating differential backups, that are not supported when backup is run on a secondary replica.
-
SECONDARY_ONLY
-
Specifies that backups should never be performed on the primary replica. If the primary replica is the only replica online, the backup should not occur.
-
SECONDARY
-
Specifies that backups should occur on a secondary replica except when the primary replica is the only replica online. In that case, the backup should occur on the primary replica. This is the default behavior.
-
NONE
-
Specifies that you prefer that backup jobs ignore the role of the availability replicas when choosing the replica to perform backups. Note backup jobs might evaluate other factors such as backup priority of each availability replica in combination with its operational state and connected state.
There is no enforcement of the AUTOMATED_BACKUP_PREFERENCE setting. The interpretation of this preference depends on the logic, if any, that you script into back jobs for the databases in a given availability group. For more information, see Active Secondaries: Backup on Secondary Replicas (AlwaysOn Availability Groups).
Note
|
|
To view the automated backup preference of an existing availability group, select the automated_backup_preference or automated_backup_preference_desc column of the sys.availability_groups catalog view.
|
-
FAILURE_CONDITION_LEVEL = { 1 | 2 | 3 | 4 | 5 }
-
Specifies what failure conditions will trigger an automatic failover for this availability group. FAILURE_CONDITION_LEVEL is set at the group level but is relevant only on availability replicas that are configured for synchronous-commit availability mode (AVAILIBILITY_MODE = SYNCHRONOUS_COMMIT). Furthermore, failure conditions can trigger an automatic failover only if both the primary and secondary replicas are configured for automatic failover mode (FAILOVER_MODE = AUTOMATIC) and the secondary replica is currently synchronized with the primary replica.
The failure-condition levels (1–5) range from the least restrictive, level 1, to the most restrictive, level 5. A given condition level encompasses all the less restrictive levels. Thus, the strictest condition level, 5, includes the four less restrictive condition levels (1-4), level 4 includes levels 1-3, and so forth. The following table describes the failure-condition that corresponds to each level.
|
Level
|
Failure Condition
|
|
1
|
Specifies that an automatic failover should be initiated when any of the following occurs:
-
The SQL Server service is down.
-
The lease of the availability group for connecting to the WSFC cluster expires because no ACK is received from the server instance. For more information, see How It Works: SQL Server AlwaysOn Lease Timeout.
|
|
2
|
Specifies that an automatic failover should be initiated when any of the following occurs:
-
The instance of SQL Server does not connect to cluster, and the user-specified HEALTH_CHECK_TIMEOUT threshold of the availability group is exceeded.
-
The availability replica is in failed state.
|
|
3
|
Specifies that an automatic failover should be initiated on critical SQL Server internal errors, such as orphaned spinlocks, serious write-access violations, or too much dumping.
This is the default behavior.
|
|
4
|
Specifies that an automatic failover should be initiated on moderate SQL Server internal errors, such as a persistent out-of-memory condition in the SQL Server internal resource pool.
|
|
5
|
Specifies that an automatic failover should be initiated on any qualified failure conditions, including:
|
Note
|
|
Lack of response by an instance of SQL Server to client requests is not relevant to availability groups.
|
The FAILURE_CONDITION_LEVEL and HEALTH_CHECK_TIMEOUT values, define a flexible failover policy for a given group. This flexible failover policy provides you with granular control over what conditions must cause an automatic failover. For more information, see Flexible Failover Policy for Automatic Failover of an Availability Group (SQL Server).
-
HEALTH_CHECK_TIMEOUT = milliseconds
-
Specifies the wait time (in milliseconds) for the sp_server_diagnostics system stored procedure to return server-health information before the WSFC cluster assumes that the server instance is slow or hung. HEALTH_CHECK_TIMEOUT is set at the group level but is relevant only on availability replicas that are configured for synchronous-commit availability mode with automatic failover (AVAILIBILITY_MODE = SYNCHRONOUS_COMMIT). Furthermore, a health-check timeout can trigger an automatic failover only if both the primary and secondary replicas are configured for automatic failover mode (FAILOVER_MODE = AUTOMATIC) and the secondary replica is currently synchronized with the primary replica.
The default HEALTH_CHECK_TIMEOUT value is 30000 milliseconds (30 seconds). The minimum value is 15000 milliseconds (15 seconds), and the maximum value is 4294967295 milliseconds.
Important
|
|
sp_server_diagnostics does not perform health checks at the database level.
|
-
DATABASE database_name
-
Specifies a list of one or more user databases on the local SQL Server instance (that is, the server instance on which you are creating the availability group). You can specify multiple databases for an availability group, but each database can belong to only one availability group. For information about the type of databases that an availability group can support, see Prerequisites, Restrictions, and Recommendations for AlwaysOn Availability Groups (SQL Server). To find out which local databases already belong to an availability group, see the replica_id column in the sys.databases catalog view.
The DATABASE clause is optional. If you omit it, the new availability group will be empty.
After you have created the availability group, you will need connect to each server instance that hosts a secondary replica and then prepare each secondary database and join it to the availability group. For more information, see Start Data Movement on an AlwaysOn Secondary Database (SQL Server).
Note
|
|
Later, you can add eligible databases on the server instance that hosts the current primary replica to an availability group. You can also remove a database from an availability group. For more information, see ALTER AVAILABILITY GROUP (Transact-SQL).
|
-
REPLICA ON
-
Specifies from one to five SQL server instances to host availability replicas in the new availability group. Each replica is specified by its server instance address followed by a WITH (…) clause. Minimally, you must specify your local server instance, which will become the initial primary replica. Optionally, you can also specify up to four secondary replicas.
You need to join every secondary replica to the availability group. For more information, see ALTER AVAILABILITY GROUP (Transact-SQL).
Note
|
|
If you specify less than four secondary replicas when you create an availability group, you can an additional secondary replica at any time by using the ALTER AVAILABILITY GROUP Transact-SQL statement. You can also use this statement this remove any secondary replica from an existing availability group.
|
-
<server_instance>
-
Specifies the address of the instance of SQL Server that is the host for an replica. The address format depends on whether the instance is the default instance or a named instance and whether it is a standalone instance or a failover cluster instance (FCI), as follows:
{ 'system_name[\instance_name]' | 'FCI_network_name[\instance_name]' }
The components of this address are as follows:
-
system_name
-
Is the NetBIOS name of the computer system on which the target instance of SQL Server resides. This computer must be a WSFC node.
-
FCI_network_name
-
Is the network name that is used to access a SQL Server failover cluster. Use this if the server instance participates as a SQL Server failover partner. Executing SELECT @@SERVERNAME on an FCI server instance returns its entire 'FCI_network_name[\instance_name]' string (which is the full replica name).
-
instance_name
-
Is the name of an instance of a SQL Server that is hosted by system_name or FCI_network_name and that has HADR service is enabled. For a default server instance, instance_name is optional. The instance name is case insensitive. On a stand-alone server instance, this value name is the same as the value returned by executing SELECT @@SERVERNAME.
-
\
-
Is a separator used only when specifying instance_name, in order to separate it from system_name or FCI_network_name.
For information about the prerequisites for WSFC nodes and server instances, see Prerequisites, Restrictions, and Recommendations for AlwaysOn Availability Groups (SQL Server).
-
ENDPOINT_URL = 'TCP://system-address:port'
-
Specifies the URL path for the database mirroring endpoint on the instance of SQL Server that will host the availability replica that you are defining in your current REPLICA ON clause.
The ENDPOINT_URL clause is required. For more information, see Specify the Endpoint URL When Adding or Modifying an Availability Replica (SQL Server).
-
'TCP://system-address:port'
-
Specifies a URL for specifying an endpoint URL or read-only routing URL. The URL parameters are as follows:
-
system-address
-
Is a string, such as a system name, a fully qualified domain name, or an IP address, that unambiguously identifies the destination computer system.
-
port
-
Is a port number that is associated with the mirroring endpoint of the partner server instance (for the ENDPOINT_URL option) or the port number used by the Database Engine of the server instance (for the READ_ONLY_ROUTING_URL option).
-
AVAILABILITY_MODE = { SYNCHRONOUS_COMMIT | ASYNCHRONOUS_COMMIT }
-
Specifies whether the primary replica has to wait for the secondary replica to acknowledge the hardening (writing) of the log records to disk before the primary replica can commit the transaction on a given primary database. The transactions on different databases on the same primary replica can commit independently.
-
SYNCHRONOUS_COMMIT
-
Specifies that the primary replica will wait to commit transactions until they have been hardened on this secondary replica (synchronous-commit mode). You can specify SYNCHRONOUS_COMMIT for up to three replicas, including the primary replica.
-
ASYNCHRONOUS_COMMIT
-
Specifies that the primary replica commits transactions without waiting for this secondary replica to harden the log (synchronous-commit availability mode). You can specify ASYNCHRONOUS_COMMIT for up to five availability replicas, including the primary replica.
The AVAILABILITY_MODE clause is required. For more information, see Availability Modes (AlwaysOn Availability Groups).
-
FAILOVER_MODE = { AUTOMATIC | MANUAL }
-
Specifies the failover mode of the availability replica that you are defining.
-
AUTOMATIC
-
Enables automatic failover. This option is supported only if you also specify AVAILABILITY_MODE = SYNCHRONOUS_COMMIT. You can specify AUTOMATIC for two availability replicas, including the primary replica.
Note
|
|
SQL Server Failover Cluster Instances (FCIs) do not support automatic failover by availability groups, so any availability replica that is hosted by an FCI can only be configured for manual failover.
|
-
MANUAL
-
Enables planned manual failover or forced manual failover (typically called forced failover) by the database administrator.
The FAILOVER_MODE clause is required. The two types of manual failover, manual failover without data loss and forced failover (with possible data loss), are supported under different conditions. For more information, see Failover and Failover Modes (AlwaysOn Availability Groups).
-
BACKUP_PRIORITY = n
-
Specifies your priority for performing backups on this replica relative to the other replicas in the same availability group. The value is an integer in the range of 0..100. These values have the following meanings:
-
1..100 indicates that the availability replica could be chosen for performing backups. 1 indicates the lowest priority, and 100 indicates the highest priority. If BACKUP_PRIORITY = 1, the availability replica would be chosen for performing backups only if no higher priority availability replicas are currently available.
-
0 indicates that this availability replica will never be chosen for performing backups. This is useful, for example, for a remote availability replica to which you never want backups to fail over.
For more information, see Active Secondaries: Backup on Secondary Replicas (AlwaysOn Availability Groups).
-
SECONDARY_ROLE ( … )
-
Specifies role-specific settings that will take effect if this availability replica currently owns the secondary role (that is, whenever it is a secondary replica). Within the parentheses, specify either or both secondary-role options. If you specify both, use a comma-separated list.
The secondary role options are as follows:
-
ALLOW_CONNECTIONS = { NO | READ_ONLY | ALL }
-
Specifies whether the databases of a given availability replica that is performing the secondary role (that is, is acting as a secondary replica) can accept connections from clients, one of:
-
NO
-
No user connections are allowed to secondary databases of this replica. They are not available for read access. This is the default behavior.
-
READ_ONLY
-
Only connections are allowed to the databases in the secondary replica where the Application Intent property is set to ReadOnly. For more information about this property, see Using Connection String Keywords with SQL Server Native Client.
-
ALL
-
All connections are allowed to the databases in the secondary replica for read-only access.
For more information, see Active Secondaries: Readable Secondary Replicas (AlwaysOn Availability Groups).
-
READ_ONLY_ROUTING_URL = 'TCP://system-address:port'
-
Specifies the URL to be used for routing read-intent connection requests to this availability replica. This is the URL on which the SQL Server Database Engine listens. Typically, the default instance of the SQL Server Database Engine listens on TCP port 1433.
For a named instance, you can obtain the port number by querying the port and type_desc columns of the sys.dm_tcp_listener_states dynamic management view. The server instance uses the Transact-SQL listener (type_desc = 'TSQL').
For more information about calculating the read-only routing URL for an availability replica, see Calculating read_only_routing_url for AlwaysOn.
-
PRIMARY_ROLE ( … )
-
Specifies role-specific settings that will take effect if this availability replica currently owns the primary role (that is, whenever it is the primary replica). Within the parentheses, specify either or both primary-role options. If you specify both, use a comma-separated list.
The primary role options are as follows:
-
ALLOW_CONNECTIONS = { READ_WRITE | ALL }
-
Specifies the type of connection that the databases of a given availability replica that is performing the primary role (that is, is acting as a primary replica) can accept from clients, one of:
-
READ_WRITE
-
Connections where the Application Intent connection property is set to ReadOnly are disallowed. When the Application Intent property is set to ReadWrite or the Application Intent connection property is not set, the connection is allowed. For more information about Application Intent connection property, see Using Connection String Keywords with SQL Server Native Client.
-
ALL
-
All connections are allowed to the databases in the primary replica. This is the default behavior.
-
READ_ONLY_ROUTING_LIST = { (‘<server_instance>’ [ ,...n ] ) | NONE }
-
Specifies a comma-separated list of server instances that host availability replicas for this availability group that meet the following requirements when running under the secondary role:
-
Be configured to allow all connections or read-only connections (see the ALLOW_CONNECTIONS argument of the SECONDARY_ROLE option, above).
-
Have their read-only routing URL defined (see the READ_ONLY_ROUTING_URL argument of the SECONDARY_ROLE option, above).
The READ_ONLY_ROUTING_LIST values are as follows:
-
<server_instance>
-
Specifies the address of the instance of SQL Server that is the host for an availability replica that is a readable secondary replica when running under the secondary role.
Use a comma-separated list to specify all the server instances that might host a readable secondary replica. Read-only routing will follow the order in which server instances are specified in the list. If you include a replica's host server instance on the replica's read-only routing list, placing this server instance at the end of the list is typically a good practice, so that read-intent connections go to a secondary replica, if one is available.
-
NONE
-
Specifies that when this availability replica is the primary replica, read-only routing will not be supported. This is the default behavior.
-
SESSION_TIMEOUT = integer
-
Specifies the session-timeout period in seconds. If you do not specify this option, by default, the time period is 10 seconds. The minimum value is 5 seconds.
Important
|
|
We recommend that you keep the time-out period at 10 seconds or greater.
|
For more information about the session-timeout period, see Overview of AlwaysOn Availability Groups (SQL Server).
-
LISTENER ‘dns_name’ ( <listener_option> )
-
Defines a new availability group listener for this availability group. LISTENER is an optional argument.
Important
|
|
Before you create your first listener, we strongly recommend that you read Prerequisites, Restrictions, and Recommendations for AlwaysOn Client Connectivity (SQL Server).
After you create a listener for a given availability group, we strongly recommend that you do the following:
-
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.
|
-
dns_name
-
Specifies the DNS host name of the availability group listener. The DNS name of the listener must be unique in the domain and in NetBIOS.
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.
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.
|
-
<listener_option>
-
LISTENER takes one of the following <listener_option> options:
-
WITH DHCP [ ON { (‘four_part_ipv4_address’,‘four_part_ipv4_mask’) } ]
-
Specifies that the availability group listener will use the Dynamic Host Configuration Protocol (DHCP). Optionally, use the ON clause to identify the network on which this listener will be created. DHCP is limited to a single subnet that is used for every server instances that hosts an availability replica in the availability group.
Important
|
|
We do not recommend DHCP in production environment. If there is a down time and the DHCP IP lease expires, extra time is required to register the new DHCP network IP address that is associated with the listener DNS name and impact the client connectivity. However, DHCP is good for setting up your development and testing environment to verify basic functions of availability groups and for integration with your applications.
|
For example:
WITH DHCP ON ('10.120.19.0','255.255.254.0')
-
WITH IP ( { (‘four_part_ipv4_address’,‘four_part_ipv4_mask’) | (‘ipv6_address’) } [ , ...n ] ) [ , PORT =listener_port ]
-
Specifies that, instead of using DHCP, the availability group listener will use one or more static IP addresses. To create an availability group across multiple subnets, each subnet requires one static IP address in the listener configuration. For a given subnet, the static IP address can be either an IPv4 address or an IPv6 address. Contact your network administrator to get a static IP address for each subnet that will host an availability replica for the new availability group.
For example:
WITH IP ( ('10.120.19.155','255.255.254.0') )
-
four_part_ipv4_address
-
Specifies an IPv4 four-part address for an availability group listener. For example, 10.120.19.155.
-
four_part_ipv4_mask
-
Specifies an IPv4 four-part mask for an availability group listener. For example, 255.255.254.0.
-
ipv6_address
-
Specifies an IPv6 address for an availability group listener. For example, 2001::4898:23:1002:20f:1fff:feff:b3a3.
-
PORT = listener_port
-
Specifies the port number—listener_port—to be used by an availability group listener that is specified by a WITH IP clause. PORT is optional.
The default port number, 1433, is supported. However, if you have security concerns, we recommend using a different port number.
For example: WITH IP ( ('2001::4898:23:1002:20f:1fff:feff:b3a3') ) , PORT = 7777