Question

Very frequently when I restore databases the restore operation gets stuck and the wait type is ASYNC_IO_COMPLETION. It can be in such state for 10-20-30 minutes untill it proceeds to PREEMPTIVE_OS_WRITEFILEGATHER and this is when progress (percent_complete) starts to grow.

However, if I see ASYNC_IO_COMPLETION and interrupt the process of restore and then run it again, I immediately see PREEMPTIVE_OS_WRITEFILEGATHER and percent_complete goes up.

It would be good to understand this behaviour and learn if there is a more proper way to speed up the restore operation. Thank you

Was it helpful?

Solution

Try to enable "Instant File Initialization" feature if it is not enabled already. It speeds up the restore process and makes it significantly faster.

What is Instant File Initialization(IFI)?

SQL Server needs to initialize the pages before using them. Thus, it tries to fill the pages with zeros(zeroing the files). If IFI is enabled, it skips this part and data files can be initialized instantaneously to avoid zeroing operations.

How to enable IFI?

Unfortunately, there is no in-built checkbox or trace flag to enable this feature. Instead, SQL Server service account needs to have "Perform Volume Maintenance Tasks" permission. Check out below page for detailed steps on how to do that.

MS Documentation: Instant File Initialization

When it will be enabled?

Be aware of that you need to restart SQL Server service so that SQL service will pick this policy up and enable this cool feature.

Bonus: You can check SQL Error Log to see whether IFI is enabled or not. Use " "Filter" to search for keywords such as "Instant", "Initialization" or You may use below query taken from this blog post.

SELECT  @@SERVERNAME AS [Server Name] ,
    RIGHT(@@version, LEN(@@version) - 3 - CHARINDEX(' ON ', @@VERSION)) AS [OS Info] ,
    LEFT(@@VERSION, CHARINDEX('-', @@VERSION) - 2) + ' '
    + CAST(SERVERPROPERTY('ProductVersion') AS NVARCHAR(300)) AS [SQL Server Version] ,
    service_account ,
    instant_file_initialization_enabled FROM sys.dm_server_services WHERE servicename LIKE 'SQL Server (%'
Licensed under: CC-BY-SA with attribution
Not affiliated with dba.stackexchange
scroll top