Skip to content

The PREEMPTIVE_OS_CREATEFILE Wait Type in SQL Server


Understanding the PREEMPTIVE_OS_CREATEFILE Wait Type in SQL Server

Need help with this wait type or others, Stedman Solutions can help. Find out how with a free no risk 30 minute consultation with Steve Stedman.

If you’re a SQL Server administrator or developer, you might have encountered the PREEMPTIVE_OS_CREATEFILE wait type while troubleshooting performance issues. While it’s not one of the most common wait types, understanding its implications can help you optimize your database environment. In this blog post, we’ll dive into what this wait type means, why it occurs, and how you can address it.

What is PREEMPTIVE_OS_CREATEFILE?

The PREEMPTIVE_OS_CREATEFILE wait type is associated with SQL Server interacting with the operating system in a preemptive mode. Specifically, it indicates that a thread in SQL Server is waiting for the operating system to complete a file creation operation. This typically happens when SQL Server needs to create a new file, such as during database file growth, log file initialization, or when creating temporary files.

SQL Server operates in two scheduling modes:

  • Cooperative mode: SQL Server manages its own threads using its internal scheduler.
  • Preemptive mode: SQL Server hands off control to the operating system for certain tasks, like file I/O operations, that require external resources.

Wait types starting with PREEMPTIVE_ indicate that SQL Server is waiting on the OS, and PREEMPTIVE_OS_CREATEFILE specifically points to file creation delays.

Common Causes

This wait type can surface for several reasons, including:

  1. Database File Growth: When a data or log file reaches its current capacity and auto-growth kicks in, SQL Server needs to create additional space on disk.
  2. Instant File Initialization (IFI) Not Enabled: Without IFI, SQL Server must zero out the new file space, which can significantly increase the time spent waiting.
  3. Slow Disk I/O: If the underlying storage system is slow (e.g., high latency or contention), file creation operations can take longer.
  4. Temporary File Creation: Operations like creating snapshots or tempdb files might also trigger this wait type.

How to Investigate

To dig into PREEMPTIVE_OS_CREATEFILE waits, start by querying the sys.dm_os_wait_stats dynamic management view (DMV). Here’s a sample query:

SELECT wait_type, waiting_tasks_count, wait_time_msFROM sys.dm_os_wait_statsWHERE wait_type = 'PREEMPTIVE_OS_CREATEFILE'ORDER BY wait_time_ms DESC;

If you see a high wait_time_ms or waiting_tasks_count, it’s a sign that this wait type is impacting performance. Next, correlate this with:

  • File Growth Events: Check the SQL Server error log or use sys.dm_db_file_space_usage to see if auto-growth is frequent.
  • Disk Performance: Use tools like PerfMon to monitor disk latency and IOPS.

Mitigating PREEMPTIVE_OS_CREATEFILE Waits

Here are some practical steps to reduce or eliminate these waits:

  1. Enable Instant File Initialization: IFI allows SQL Server to skip zeroing out new file space, drastically reducing file creation time. Grant the SQL Server service account the “Perform Volume Maintenance Tasks” permission in Windows.
  2. Pre-Allocate Database Files: Instead of relying on auto-growth, manually size your data and log files to accommodate expected workloads.
  3. Optimize Auto-Growth Settings: If auto-growth is necessary, set it to a reasonable fixed size (e.g., 512 MB) rather than a small increment or percentage, which can lead to frequent growth events.
  4. Improve Storage Performance: Work with your storage team to ensure the underlying disks can handle file creation efficiently.

Conclusion

The PREEMPTIVE_OS_CREATEFILE wait type might not always be a major bottleneck, but when it appears prominently in your wait stats, it’s a signal to investigate file management and storage performance. By enabling IFI, pre-sizing files, and optimizing your disk subsystem, you can minimize these waits and keep your SQL Server running smoothly.

Need help with this wait type or others, Stedman Solutions can help. Need performance help, we can help with a comprehensive performance assessment? Need help on an ongoing basis, our managed services can help.Find out how Stedman Solutions can help you with a free no risk 30 minute consultation with Steve Stedman to find out how we can best help with your SQL Server needs.

https://stedman.us/30

Getting Help from Steve and the Stedman Solutions Team
We are ready to help. Steve and the team at Stedman Solutions are here to help with your SQL Server needs. Get help today by contacting Stedman Solutions through the free 30 minute consultation form.

Contact Info for Stedman Solutions, LLC. --- PO Box 3175, Ferndale WA 98248, Phone: (360)610-7833
Our Privacy Policy