Skip to content

Commit 6a9900f

Browse files
authored
Merge pull request MicrosoftDocs#2440 from WilliamAntonRohm/w-auto-seeding-secondaries
new article Automatic Seeding of Secondary Replicas
2 parents f5266a3 + 07feb7a commit 6a9900f

File tree

4 files changed

+227
-0
lines changed

4 files changed

+227
-0
lines changed

docs/database-engine/availability-groups/windows/TOC.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
# Concepts
1717
## [Automatic seeding](automatically-initialize-always-on-availability-group.md)
18+
## [Automatic seeding for secondary replicas](automatic-seeding-secondary-replicas.md)
1819
## [Availability group policies](always-on-policies-for-operational-issues-always-on-availability.md)
1920
## [Availability modes](availability-modes-always-on-availability-groups.md)
2021
## [Backup on secondary](active-secondaries-backup-on-secondary-replicas-always-on-availability-groups.md)
Lines changed: 226 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,226 @@
1+
---
2+
title: "Automatic seeding for secondary replicas (SQL Server) | Microsoft Docs"
3+
description: "Use automatic seeding to initialize secondary replicas."
4+
services: data-lake-analytics
5+
ms.custom: ""
6+
ms.date: "06/22/2017"
7+
ms.prod: "sql-server-2016"
8+
ms.reviewer: ""
9+
ms.suite: ""
10+
ms.technology:
11+
- "dbe-high-availability"
12+
ms.tgt_pltfrm: ""
13+
ms.topic: "article"
14+
helpviewer_keywords:
15+
- "Automatic seeding [SQL Server], secondary replica"
16+
ms.assetid:
17+
caps.latest.revision:
18+
author: "MikeRayMSFT"
19+
ms.author: "mikeray"
20+
manager: "jhubbard"
21+
---
22+
# Automatic seeding for secondary replicas
23+
24+
[!INCLUDE [tsql-appliesto-ss2016-xxxx-xxxx-xxx_md](../../../includes/tsql-appliesto-ss2016-xxxx-xxxx-xxx-md.md)]
25+
26+
In SQL Server 2012 and 2014, the only way to initialize a secondary replica in an availability group is to use backup, copy, and restore. SQL Server 2016 introduces a new feature to initialize a secondary replica – *automatic seeding*. Automatic seeding uses the log stream transport to stream the backup using VDI to the secondary replica for each database of the availability group using the configured endpoints. This new feature can be used either during the initial creation of an availability group or when a database is added to one. Automatic seeding is in all editions of SQL Server that support Always On availability groups, and can be used with both traditional availability groups and [distributed availability groups](distributed-availability-groups.md).
27+
28+
## Considerations
29+
30+
Considerations for using automatic seeding include:
31+
32+
* [Performance and transaction log impact on the primary replica](#performance-and-transaction-log-impact-on-the-primary-replica)
33+
* [Disk layout](#disk-layout)
34+
* [Security](#security)
35+
36+
37+
### Performance and transaction log impact on the primary replica
38+
39+
Automatic seeding may or may not practical to initialize a secondary replica, depending on the size of the database, network speed, and distance between the primary and secondary replicas. For example, given:
40+
41+
* The database size is 5 TB
42+
* The network speed is 1Gb/sec
43+
* The distance between the two sites is 1000 miles
44+
45+
A 1Gb/sec network can provide sustained throughput of 125 MB/sec if the full bandwidth is available. In this example, automatic seeding would take just over 11 hours. In practice, the automatic seeding process is somewhat slower, as network signals degrade over longer distances and the link is usually shared with other resources on the network. During seeding, the transaction log on the database at the primary replica will continue to grow and cannot be truncated until automatic seeding of that database is complete. The transaction log can then be truncated using a transaction log backup.
46+
47+
Automatic seeding is a single-threaded process that can handle up to five databases. This may affect performance, especially if the availability group has more than one database.
48+
49+
Compression can be used for automatic seeding, but it is disabled by default. Turning on compression reduces network bandwidth and possibly speeds up the process, but the tradeoff is additional processor overhead. To use compression during automatic seeding, enable trace flag 9567 - see [Tune compression for availability group](tune-compression-for-availability-group.md).
50+
51+
### Disk layout
52+
53+
The folder where the database will be created by automatic seeding must already exist and be the same as the path on the primary replica.
54+
55+
### Security
56+
57+
Security permissions vary depending on the type of replica being initialized:
58+
59+
* For a traditional availability group, permissions must be granted to the availability group on the secondary replica as it is joined to the availability group. In Transact-SQL, use the command ALTER AVAILABILITY GROUP [AGName] GRANT CREATE ANY DATABASE.
60+
* For a distributed availability group where the replica’s databases that are being created are on the primary replica of the second availability group, no extra permissions are required as it is already a primary.
61+
* For a secondary replica on the second availability group of a distributed availability group, you must use the command ALTER AVAILABILITY GROUP [2ndAGName] GRANT CREATE ANY DATABASE. This secondary replica will be seeded from the primary of the second availability group.
62+
63+
## Create an availability group with automatic seeding
64+
65+
You create an availability group using automatic seeding with either Transact-SQL or SQL Server Management Studio (SSMS, version 17 or later). To use the Availability Group Wizard in SSMS, follow [these instructions](use-the-availability-group-wizard-sql-server-management-studio.md) - when you get to Step 9, you will see automatic seeding as the first, and default, option.
66+
67+
![Select initial data synchronization][1]
68+
69+
The following example creates an availability group using Transact-SQL. See also the topic [Create an Availability Group (Transact-SQL)](create-an-availability-group-transact-sql.md). Seeding is enabled on a secondary replica by setting the SEEDING_MODE option to AUTOMATIC. The default behavior is MANUAL, which is the pre-SQL Server 2016 behavior requiring a backup of the database to be made on the primary replica, a copy of the backup file to the secondary replica, and a restore of the backup WITH NORECOVERY.
70+
71+
```
72+
CREATE AVAILABILITY GROUP [AGName]
73+
FOR DATABASE db1
74+
REPLICA ON N'Primary_Replica'
75+
WITH (
76+
ENDPOINT_URL = N'TCP://Primary_Replica.Contoso.com:5022',
77+
FAILOVER_MODE = AUTOMATIC,
78+
AVAILABILITY_MODE = SYNCHRONOUS_COMMIT,
79+
),
80+
N'Secondary_Replica' WITH (
81+
ENDPOINT_URL = N'TCP://Secondary_Replica.Contoso.com :5022',
82+
FAILOVER_MODE = AUTOMATIC,
83+
SEEDING_MODE = AUTOMATIC);
84+
GO
85+
```
86+
87+
Setting SEEDING_MODE on a primary replica during a CREATE AVAILABILITY GROUP statement has no effect since the primary replica already contains the main read/write copy of the database. SEEDING_MODE would only apply when another replica was made the primary and a database was added. The seeding mode can be changed later - see [Change the seeding mode of a replica](#change-the-seeding-mode-of-a-replica).
88+
89+
On an instance that becomes a secondary replica, once the instance is joined the following message is added to the SQL Server Log:
90+
91+
Local availability replica for availability group 'AGName' has not been granted permission to create databases, but has a SEEDING_MODE of AUTOMATIC. Use the ALTER AVAILABILITY GROUP … GRANT CREATE ANY DATABASE command to allow the creation of databases seeded by the primary availability replica.
92+
93+
After joining, issue the following statement:
94+
95+
```
96+
ALTER AVAILABILITY GROUP [AGName] GRANT CREATE ANY DATABASE
97+
GO
98+
````
99+
100+
> [!NOTE]
101+
> There is currently a known issue as of SQL Server 2016 SP1 CU2 where a secondary replica must wait three minutes to allow the AG to seed the database before executing an ALTER AVAILABILITY GROUP... statement. Before that time elapses, the statement will not return an error, rather it will indicate success. This is also a known issue. These issues will be fixed in a future update to SQL Server. As a workaround, insert a WAITFOR statement:
102+
103+
```
104+
WAITFOR DELAY '00:03:15';
105+
ALTER AVAILABILITY GROUP [AGName] GRANT CREATE ANY DATABASE;
106+
GO
107+
```
108+
109+
If successful, the database(s) are automatically created on the secondary replica with a state of either:
110+
111+
* SYNCHRONIZED if the secondary replica is configured to be synchronous and the data is completely synchronized.
112+
* SYNCHRONIZING if the secondary replica is configured with asynchronous data movement, or when configured with synchronous but not yet synchronized with the primary replica.
113+
114+
<a name="sql-server-log"></a>
115+
In addition to the [Dynamic Management Views](#dynamic-management-views) described below, the start and completion of automatic seeding can be seen in the SQL Server Log:
116+
117+
![SQL server log][2]
118+
119+
## Combine backup and restore with automatic seeding
120+
121+
It is possible to combine the traditional backup, copy, and restore with automatic seeding. In this case, first restore the database on a secondary replica including all available transaction logs. Next, enable automatic seeding when creating the availability group to "catch up" the secondary replica’s database, as if a tail-log backup were restored (see [Tail-Log Backups (SQL Server)](../../../relational-databases/backup-restore/tail-log-backups-sql-server.md)).
122+
123+
## Add a database to an availability group with automatic seeding
124+
125+
You can add a database to an availability group using automatic seeding using Transact-SQL or SQL Server Management Studio (SSMS, version 17 or later).
126+
If the secondary replica used automatic seeding when it was added to the availability group, nothing additional needs to be done. If backup, copy, and restore was used, first change the seeding mode (see next section) and then when adding the database use the GRANT statement - see [Availability Group - Add a Database](availability-group-add-a-database.md).
127+
128+
## Change the seeding mode of a replica
129+
130+
A replica’s seeding mode can be altered after the availability group is created, so automatic seeding can be enabled or disabled. Enabling automatic seeding after creation allows a database to be added to the availability group using automatic seeding if it was created with backup, copy, and restore. For example:
131+
132+
```
133+
ALTER AVAILABILITY GROUP [AGName]
134+
MODIFY REPLICA ON 'Replica_Name'
135+
WITH (SEEDING_MODE = AUTOMATIC)
136+
```
137+
138+
To disable automatic seeding, use a value of MANUAL.
139+
140+
## Prevent automatic seeding after an availability group is created
141+
142+
If you do not want to disable automatic seeding completely for a secondary replica, but want to temporarily prevent the secondary replica from being able to automatically create databases, deny the availability group CREATE permission. This is the case when a new database is added to the availability group, but the availability group should not be allowed to create the database on a secondary replica.
143+
144+
```
145+
ALTER AVAILABILITY GROUP [AGName] DENY CREATE ANY DATABASE
146+
GO
147+
```
148+
149+
## Monitor automatic seeding
150+
151+
There are four ways to monitor and troubleshoot automatic seeding:
152+
153+
* [SQL Server Log](#sql-server-log) as already described
154+
* [Dynamic management views](#dynamic-management-views)
155+
* [Backup history tables](#backup-history-tables)
156+
* [Extended events](#extended-events)
157+
158+
### Dynamic Management Views
159+
160+
There are two dynamic management views (DMVs) for monitoring seeding: sys.dm_hadr_automatic_seeding and sys.dm_hadr_physical_seeding_stats.
161+
162+
* sys.dm_hadr_automatic_seeding contains the general status of automatic seeding, and retains the history for each time it is executed (whether successful or not). The column current_state will have either a value of COMPLETED or FAILED. If the value is FAILED, use the value in failure_state_desc to help in diagnosing the problem. You may need to combine that with what it in the [SQL Server Log](#sql-server-log) to see what went wrong. This DMV is populated on the primary replica and all secondary replicas.
163+
164+
* sys.dm_hadr_physical_seeding_stats shows the status of the automatic seeding operation as it is executing. As with sys.dm_hadr_automatic_seeding, this will show values on both the primary and secondary replicas, but this history is not stored. The values are for the current execution only, and will not be retained. Columns of interest include start_time_utc, end_time_utc, estimate_time_complete_utc, total_disk_io_wait_time_ms, total_network_wait_time_ms, and if the seeding operation fails, failure_message.
165+
166+
### Backup history tables
167+
168+
Automatic seeding also puts entries into the `msdb` tables which store the history for backups and restores. On the secondary replica which is receiving automatic seeding, the `backupmediafamily` table's physical_device_name column has a GUID for its value, and the corresponding entry in `backupset` has the name of the primary replica for server_name and machine_name.
169+
170+
### Extended events
171+
172+
Automatic seeding adds new extended events for tracking state change, failures, and performance statistics during initialization.
173+
For example, the following script creates an extended events session that captures events related to automatic seeding.
174+
175+
```
176+
CREATE EVENT SESSION [AG_autoseed] ON SERVER
177+
ADD EVENT sqlserver.hadr_automatic_seeding_state_transition,
178+
ADD EVENT sqlserver.hadr_automatic_seeding_timeout,
179+
ADD EVENT sqlserver.hadr_db_manager_seeding_request_msg,
180+
ADD EVENT sqlserver.hadr_physical_seeding_backup_state_change,
181+
ADD EVENT sqlserver.hadr_physical_seeding_failure,
182+
ADD EVENT sqlserver.hadr_physical_seeding_forwarder_state_change,
183+
ADD EVENT sqlserver.hadr_physical_seeding_forwarder_target_state_change,
184+
ADD EVENT sqlserver.hadr_physical_seeding_progress,
185+
ADD EVENT sqlserver.hadr_physical_seeding_restore_state_change,
186+
ADD EVENT sqlserver.hadr_physical_seeding_submit_callback
187+
ADD TARGET package0.event_file(SET filename=N’autoseed.xel’,max_file_size=(5),max_rollover_files=(4))
188+
WITH (MAX_MEMORY=4096 KB,EVENT_RETENTION_MODE=ALLOW_SINGLE_EVENT_LOSS,MAX_DISPATCH_LATENCY=30 SECONDS,MAX_EVENT_SIZE=0 KB,MEMORY_PARTITION_MODE=NONE,TRACK_CAUSALITY=OFF,STARTUP_STATE=ON)
189+
GO
190+
191+
ALTER EVENT SESSION AlwaysOn_autoseed ON SERVER STATE=START
192+
GO
193+
```
194+
195+
The following table lists extended events related to automatic seeding.
196+
197+
|Name|Description|
198+
|----|-----------|
199+
|hadr_db_manager_seeding_request_msg|Seeding request message.|
200+
|hadr_physical_seeding_backup_state_change|Physical seeding backup side state change.|
201+
|hadr_physical_seeding_restore_state_change|Physical seeding restore side state change.|
202+
|hadr_physical_seeding_forwarder_state_change|Physical seeding forwarder side state change.|
203+
|hadr_physical_seeding_forwarder_target_state_change|Physical seeding forwarder target side state change.|
204+
|hadr_physical_seeding_submit_callback|Physical seeding submit callback event.|
205+
|hadr_physical_seeding_failure|Physical seeding failure event.|
206+
|hadr_physical_seeding_progress|Physical seeding progress event.|
207+
|hadr_physical_seeding_schedule_long_task_failure|Physical seeding schedule long task failure event.|
208+
|hadr_automatic_seeding_start|Occurs when an automatic seeding operation is submitted.|
209+
|hadr_automatic_seeding_state_transition|Occurs when an automatic seeding operation changes state.|
210+
|hadr_automatic_seeding_success|Occurs when an automatic seeding operation succeeds.|
211+
|hadr_automatic_seeding_failure|Occurs when an automatic seeding operation fails.|
212+
|hadr_automatic_seeding_timeout|Occurs when an automatic seeding operation times out.|
213+
214+
## See also
215+
216+
[ALTER AVAILABILITY GROUP (Transact-SQL)](/sql/t-sql/statements/alter-availability-group-transact-sql)
217+
218+
[CREATE AVAILABILITY GROUP (Transact-SQL)](https://msdn.microsoft.com/library/ff878399.aspx)
219+
220+
[Always On Availability Groups Troubleshooting and Monitoring Guide](http://technet.microsoft.com/library/dn135328.aspx)
221+
222+
> This content written by [Allan Hirt](http://mvp.microsoft.com/en-us/PublicProfile/4025254?fullName=Allan%20Hirt), Microsoft Most Valued Professional.
223+
224+
<!--Image references-->
225+
[1]: ./media/auto-seed-new-availability-group.png
226+
[2]: ./media/auto-seed-sql-server-log.png
39.4 KB
Loading
93.8 KB
Loading

0 commit comments

Comments
 (0)