As a part of my consulting, I observed that there is a lot of interest in using AlwaysOn availability group. I have deployed many AlwaysOn solutions from start-to-finish. Recently I encountered an issue and in this blog, we would discuss reason of an availability database to stay in restoring mode even after using automatic seeding.
If you have not heard earlier, one of the new features in AlwaysOn which was introduced in SQL Server 2016 was “automatic seeding”. In the latest version of SSMS, we can also see the option of seeding as below.
My client used the option and their database size was huge and seeding is supposed to work faster than a backup and restore method. We started seeding and I asked them to use below query to monitor the progress of seeding.
SELECT local_database_name ,role_desc ,internal_state_desc ,transfer_rate_bytes_per_second ,transferred_size_bytes ,database_size_bytes ,start_time_utc ,end_time_utc ,estimate_time_complete_utc ,total_disk_io_wait_time_ms ,total_network_wait_time_ms ,is_compression_enabled FROM sys.dm_hadr_physical_seeding_stats
They contacted me again and told that seeding is completed but the database is still shown in “Restoring” state.
When I attempted to join, I received an error
Failed to join the database ‘HiDB’ to the availability group ‘HiAG’ on the availability replica ‘(LOCAL)’. (Microsoft.SqlServer.Smo)
An exception occurred while executing a Transact-SQL statement or batch. (Microsoft.SqlServer.ConnectionInfo)
The remote copy of database “HiDB” has not been rolled forward to a point in time that is encompassed in the local copy of the database log. (Microsoft SQL Server, Error: 1412)
This error is what tells us the exact cause of the issue. It looks like there is a log backup which happened in between seeding process. I asked them to use the blog and find SQL SERVER – Get Database Backup History for a Single Database
In this case, after running the script from my blog, we found that a backup job which was taking log backup on another replica every 15 minutes. We disabled the job and started seeding again. This time it worked without any issue.
Have you encountered some error during AlwaysOn AG? Please share via comments and help others.
Reference: Pinal Dave (https://blog.sqlauthority.com)