Friday, March 2, 2012

Configuring and Creating An AlwaysOn Availability Group in SQL Server 2012

In the previous article on AlwaysOn Availability Groups in SQL Server 2012, we looked at The Environmental Setup for An AlwaysOn Availability Group. In this article we turn our attention to the creation and configuration of the Availability Group.
There are two primary steps to creating an AlwaysOn availability group which has to be done only after successful creation of the Windows failover cluster as discussed in the previous article. Firstly enable AlwaysOn on each instance and then create the AlwaysOn Availability Group.

Enabling AlwaysOn High Availability on each SQL Server Instance

First of all you will need to enable AlwaysOn each participating SQL Server instance of the cluster or availability group (by default AlwaysOn is not enabled). Open SQL Server Configuration Manager (Start -> All Programs -> Microsoft SQL Server 2012 -> Configuration Tools) as shown below:
In SQL Server Configuration Manager, select and right-click on the SQL Server service (select the appropriate instance service) and click Properties. On the Properties page, select AlwaysOn High Availability tab and enable AlwaysOn as shown below; notice that the name of the Windows failover cluster in which this instance participates will automatically appear :
After enabling the AlwaysOn High Availability at instance/service level, you will need to restart the service for changes to take effect. Once enabled, the IsHadrEnabled property of the instance will be set to 1. Please note, if there is any changes in the Windows failover cluster that you created, you must disable and enable AlwaysOn High Availability feature once more for the changes to take effect. Also, ensure that the TCP/IP net library/protocol is enabled on the instance as only the TCP/IP protocol is supported by the availability group listener (I will discuss more about availability group listener later in this series).

Creating an AlwaysOn Availability Group

Now to create an availability group. Connect to the primary instance/replica in SSMS (SQL Server Management Studio) and then right-click on the Availability Groups node under the AlwaysOn High Availability node and click the New Availability Group Wizard as shown below:
In the New Availability Group Wizard, skip the introduction page and on the second page, specify a unique name for the availability group that you want to create, in this case I have used AlwaysOn-Demo-AG for the availability group:
On the Select Databases page of the New Availability Group Wizard, select all the databases that you wish to be part of the availability group (all databases in this availability group will failover together as group or unit). As noted before, as with database mirroring you are not required to have only one database here in case of an availability group. Remeber also that a database can be part of one and only one availability group at any time:
Please note in the above image, you can only include databases which meet certain prerequisites for including them in the availability group, for example that database should be in full recovery mode and you should have taken at least one full or differential backup of the database. If you click on the link for the database which does not meet prerequisite, a pop as shown below will appear with details:
On the Select Replicas page, under the Replicas tab of the New Availability Group Wizard, notice that the current instance name has already been included as the primary replica (read-write databases) and next you need to add secondary replicas (you need to have at least one or up to four secondary replicas). Here, can also specify the automatic failover setting/instance or synchronous commit mode. If you set a secondary replica for automatic failover, synchronous commit mode is required and will be set automatically. Next, can specify the readability setting for the secondary replica:
On the Select Replicas page under Endpoint tab, by default endpoints (database mirroring endpoints to connect to each other servers/instances) will be created for all the servers participating in the availability group. You can customize this for specific requirements or leave the default values as is:
On the Select Replicas page (under Backup preferences tab) of the New Availability Group Wizard, you need to specify the preferred location of automated backup for the databases participating in the availability group:
  • · Prefer Secondary – Takes an automatic backup on the secondary replica if one is available alterantively it takes a backup on the primary replica
  • · Secondary Only – Takes a backup of the database belonging to this availability group which should occur on current secondary replica only. Selecting this means you are basically offloading the backup operation from the primary to the secondary replica.
  • · Primary – Backups should always be taken on the current/active primary replica irrespective of the number of secondary replicas available.
  • · Any Replica – Backup of database belonging to the availability group can happen on any replica as per the backup priority specified. You can also exclude one or more replicas from the backup operation:
Description: Description: cid:image021.png@01CCCF90.03FACC70
On the Select Replicas page and under Listener tab of the New Availability Group Wizard, you need to specify whether you want to create an availability group listener with the availability group creation itself or whether you wish to create it later on. In either case, note that you can have only one availability group listener for an availability group.
So what is an availability group listener is and what does it do?
An availability group listener provides a connection point to connect to an availability group from client applications. An availability group listener directs incoming connections/requests to the current primary replica of the availability group for read-write operations or to a readable secondary replica for read-only operation. Therefore, the client does not need to know the physical name of the instance it intends to connect to, but instead it will be using the availability group listener and the availability group listener will route requests to the appropriate replica/instance.
When creating availability group listener you need to provide the below information:
· Listener DNS Name or Virtual Network Name (VNN) : This name should be unique across the domain.
· Port – The port number on which the availability group listener will listen for incoming requests. You can use the default port 1433 of SQL Server in which case the client would not be required to provide the port number when connecting. Otherwise the client will need to provide the port number as part of connection string. This port number should be defined appropriately in the firewall to allow for connections.
· Network mode – You can use either DHCP (Dynamic Host Configuration Protocol) or static IP for the availability group listener:
Here I have used DHCP but you need to use static IP addresses for the availability group listener if the availability group is spread across subnets in a multi-subnet domain. In addition, DHCP is not recommended for use in production for an availability group listener as it requires additional time to re-register if the DHCP lease expires.
On the Select Data Synchronization page, specify how you are going to synchronize your secondary replicas’ databases with the primary replica. In this case, because the database is not that large, I have chosen the first option to take a backup from the primary replica and restore them at all on the secondary replicas and for that I provided a shared location for storing the backup files which is accessible from both the primary and secondary replicas.
Alternatively you may prefer to peform the data synchronization manually or only synchronize the data if the databases are already restored on the secondary replicas, so in effect you have three data synchronization options to choose from as shown below:
On the Validation page the wizard runs the validation process to ensure that the given configuration details for the availability group can be created. In this case I chose to restore the database on the secondary replica and hence it also validates if the location for the data/log files exist on secondary replicas. If the validation fails, you can access the details by clicking the link in the Result column. Once you are finished with the validation, click Next:
On Summary page you can review your all selections and information you provided for creating and configuring the availability group. You can go back make any necerssary changes or click Finish to start creating the availability group:
Please note, using New Availability Group Wizard is not the only way to create an availability group, you can automate the process of creating an availability group by using PowerShell cmdlets or T-SQL commands. To generate T-SQL scripts for our selection or configuration information that you provided during this wizard, you can click on Script button to generate T-SQL script commands as shown in the above image for later use.
On Result page, as shown below, you can see the progress and the final status of the availability group creation process. The wizard performs a step-by-step operation for creating availability group, joining secondary replicas, taking back from the primary replica and restoring it to secondary replicas for data synchronization etc.
In the next article in the series we will examine how to connect to an Availability Group as well as maintaining and monitoring an Availability Group.
Source:

2 comments:

  1. Hi, how to setup MDS in always on? I do not want to use IIS

    ReplyDelete
  2. Hi, how to setup MDS in always on? I do not want to use IIS

    ReplyDelete