--- title: "Add a Secondary Replica to an Availability Group (SQL Server) | Microsoft Docs" ms.custom: "" ms.date: "06/14/2017" ms.prod: "sql-server-2014" ms.reviewer: "" ms.technology: high-availability ms.topic: conceptual helpviewer_keywords: - "Availability Groups [SQL Server], availability replicas" - "Availability Groups [SQL Server], configuring" ms.assetid: 6669dcce-85f9-495f-aadf-7f62cff4a9da author: MashaMSFT ms.author: mathoma manager: craigg --- # Add a Secondary Replica to an Availability Group (SQL Server) This topic describes how to add a secondary replica to an existing AlwaysOn availability group by using [!INCLUDE[ssManStudioFull](../../../includes/ssmanstudiofull-md.md)], [!INCLUDE[tsql](../../../includes/tsql-md.md)], or PowerShell in [!INCLUDE[ssCurrent](../../../includes/sscurrent-md.md)]. - **Before you begin:** [Prerequisites and Restrictions](#PrerequisitesRestrictions) [Security](#Security) - **To add a replica, using:** [SQL Server Management Studio](#SSMSProcedure) [Transact-SQL](#TsqlProcedure) [PowerShell](#PowerShellProcedure) - **Follow Up:** [After Adding a Secondary Replica](#FollowUp) ## Before You Begin We strongly recommend that you read this section before attempting to create your first availability group. ## Prerequisites and Restrictions - You must be connected to the server instance that hosts the primary replica. For more information, see [Prerequisites, Restrictions, and Recommendations for AlwaysOn Availability Groups (SQL Server)](prereqs-restrictions-recommendations-always-on-availability.md). ## Security ### Permissions Requires ALTER AVAILABILITY GROUP permission on the availability group, CONTROL AVAILABILITY GROUP permission, ALTER ANY AVAILABILITY GROUP permission, or CONTROL SERVER permission. ## Using SQL Server Management Studio **To add a replica** 1. In Object Explorer, connect to the server instance that hosts the primary replica, and expand the server tree. 2. Expand the **AlwaysOn High Availability** node and the **Availability Groups** node. 3. Right-click the availability group, and select one of the following commands: - Select the **Add Replica** command to launch the Add Replica to Availability Group Wizard. For more information, see [Use the Add Replica to Availability Group Wizard (SQL Server Management Studio)](use-the-add-replica-to-availability-group-wizard-sql-server-management-studio.md). - Alternatively, select the **Properties** command to open the **Availability Group Properties** dialog box. The steps for adding a replica in this dialog box are as follows: 1. In the **Availability Replicas** pane of the dialog box, click the **Add** button. This creates and selects a replica entry in which the blank Server Instance field is selected. 2. Enter the name of a server instance that meets the prerequisites for hosting an availability replica. To add an additional replicas, repeat the preceding steps. When you are done specifying replicas, click **OK** to complete the operation. ## Using Transact-SQL **To add a replica** 1. Connect to the instance of [!INCLUDE[ssNoVersion](../../../includes/ssnoversion-md.md)] that hosts the primary replica. 2. Add the new secondary replica to the availability group by using the ADD REPLICA ON clause of the ALTER AVAILABILITY GROUP statement. The ENDPOINT_URL, AVAILABILITY_MODE, and FAILOVER_MODE options are required in an ADD REPLICA ON clause. The other replica options- BACKUP_PRIORITY, SECONDARY_ROLE, PRIMARY_ROLE, and SESSION_TIMEOUT-are optional. For more information, see [ALTER AVAILABILITY GROUP (Transact-SQL)](/sql/t-sql/statements/alter-availability-group-transact-sql). For example, the following [!INCLUDE[tsql](../../../includes/tsql-md.md)] statement creates a new replica to an availability group named `MyAG` on the default server instance hosted by `COMPUTER04`, whose endpoint URL is `TCP://COMPUTER04.Adventure-Works.com:5022'`. This replica supports manual failover and asynchronous-commit availability mode. ```sql ALTER AVAILABILITY GROUP MyAG ADD REPLICA ON 'COMPUTER04' WITH ( ENDPOINT_URL = 'TCP://COMPUTER04.Adventure-Works.com:5022', AVAILABILITY_MODE = ASYNCHRONOUS_COMMIT, FAILOVER_MODE = MANUAL ); ``` ## Using PowerShell **To add a replica** 1. Change directory (`cd`) to the server instance that hosts the primary replica. 2. Use the **New-SqlAvailabilityReplica** cmdlet. For example, the following command adds an availability replica to an existing availability group named `MyAg`. This replica supports manual failover and asynchronous-commit availability mode. In the secondary role, this replica will support read access connections, allowing you to offload read-only processing to this replica. ```powershell $agPath = "SQLSERVER:\Sql\PrimaryServer\InstanceName\AvailabilityGroups\MyAg" $endpointURL = "TCP://PrimaryServerName.domain.com:5022" $failoverMode = "Manual" $availabilityMode = "AsynchronousCommit" $secondaryReadMode = "AllowAllConnections" New-SqlAvailabilityReplica -Name SecondaryServer\Instance ` -EndpointUrl $endpointURL ` -FailoverMode $failoverMode ` -AvailabilityMode $availabilityMode ` -ConnectionModeInSecondaryRole $secondaryReadMode ` -Path $agPath ``` > [!NOTE] > To view the syntax of a cmdlet, use the `Get-Help` cmdlet in the [!INCLUDE[ssNoVersion](../../../includes/ssnoversion-md.md)] PowerShell environment. For more information, see [Get Help SQL Server PowerShell](../../../powershell/sql-server-powershell.md). **To set up and use the SQL Server PowerShell provider** - [SQL Server PowerShell Provider](../../../powershell/sql-server-powershell-provider.md) ## Follow Up: After Adding a Secondary Replica To add a replica for an existing availability group, you must perform the following steps: 1. Connect to the server instance that is going to host the new secondary replica. 2. Join the new secondary replica to the availability group. For more information, see [Join a Secondary Replica to an Availability Group (SQL Server)](join-a-secondary-replica-to-an-availability-group-sql-server.md). 3. For each database in the availability group, create a secondary database on the server instance that is hosting the secondary replica. For more information, see [Manually Prepare a Secondary Database for an Availability Group (SQL Server)](manually-prepare-a-secondary-database-for-an-availability-group-sql-server.md). 4. Join each of the new secondary databases to the availability group. For more information, see [Join a Secondary Database to an Availability Group (SQL Server)](join-a-secondary-database-to-an-availability-group-sql-server.md). ## Related Tasks **To manage an availability replica** - [Join a Secondary Replica to an Availability Group (SQL Server)](join-a-secondary-replica-to-an-availability-group-sql-server.md) - [Remove a Secondary Replica from an Availability Group (SQL Server)](remove-a-secondary-replica-from-an-availability-group-sql-server.md) - [Configure Read-Only Access on an Availability Replica (SQL Server)](configure-read-only-access-on-an-availability-replica-sql-server.md) - [Change the Availability Mode of an Availability Replica (SQL Server)](change-the-availability-mode-of-an-availability-replica-sql-server.md) - [Change the Failover Mode of an Availability Replica (SQL Server)](change-the-failover-mode-of-an-availability-replica-sql-server.md) - [Change the Session-Timeout Period for an Availability Replica (SQL Server)](change-the-session-timeout-period-for-an-availability-replica-sql-server.md) - [Change the Session-Timeout Period for an Availability Replica (SQL Server)](change-the-session-timeout-period-for-an-availability-replica-sql-server.md) ## See Also [ALTER AVAILABILITY GROUP (Transact-SQL)](/sql/t-sql/statements/alter-availability-group-transact-sql) [Overview of AlwaysOn Availability Groups (SQL Server)](overview-of-always-on-availability-groups-sql-server.md) [Creation and Configuration of Availability Groups (SQL Server)](creation-and-configuration-of-availability-groups-sql-server.md) [Use the AlwaysOn Dashboard (SQL Server Management Studio)](use-the-always-on-dashboard-sql-server-management-studio.md) [Monitor Availability Groups (Transact-SQL)](monitor-availability-groups-transact-sql.md)