Use automatic seeding to initialize a secondary replica for an Always On SQL Server availability group works on Second try fails the first time

Starting in SQL Server 2016 and newer a new feature was introduced 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.  Note this last sentence as it is import and will be used later.  Additionally, in SQL Server 2012 and 2014, the only way to initialize a secondary replica in a SQL Server Always On availability group was to use a backup, copy, and restore process.

So running through the New Availability Group Wizard seems easy enough.  Everything is all setup and looks good except the Database specified is not on the Secondary Replica as I would have expected it would be. Instead of Removing the database from the AG Group and readding it or even deleting and starting from scratch, simply poke the automatic seeding for the availability group and issue the below command on the Primary node.

I googled the heck out of things like:"SQL Automatic Seeding works the second time but not the first" and couldn't find anything and while I actually did the remove and readd etc 6 months later the same thing is still happening and the below is the best I can come up with.
ALTER AVAILABILITY GROUP [AGName]
  MODIFY REPLICA ON 'Replica_Name'
  WITH (SEEDING_MODE = AUTOMATIC)




Additionally, I use the following script to check the status on the VDI transfer progress:

--https://www.mssqltips.com/sqlservertip/4537/sql-server-2016-availability-group-automatic-seeding/
SELECT r.session_id, r.status, r.command, r.wait_type, r.percent_complete, r.estimated_completion_time
  FROM sys.dm_exec_requests r
  JOIN sys.dm_exec_sessions s ON r.session_id = s.session_id
 WHERE r.session_id <> @@SPID
   AND s.is_user_process = 0 AND r.command like 'VDI%';


References :  Automatic seeding for secondary replicas Microsoft

Comments

Popular posts from this blog

How to mass update all or some sql server agent job step commands

SQL Monitoring for Blocking and Locking Capture and Log to table with sp_WhoIsActive or sp_BlitzWho

SQL Server General Index Naming Convention