Troubleshooting Guide: SQL Server Error 5512 – Directory Truncation Failure
Why This Error Happens
Error 5512 occurs when SQL Server 2025 attempts to truncate a directory used by a Memory-Optimized Filegroup (used for In-Memory OLTP checkpoint files) but encounters an underlying file system restriction. This is typically caused by the SQL Server service account lacking sufficient NTFS permissions on the data folder, antivirus or backup software locking the checkpoint files during the operation, or file system corruption on the volume hosting the filegroup. In rarer cases, this happens because the directory contains residual files from an improperly shut down instance, preventing Windows from fully clearing the folder.
Step-by-Step Resolution Guide
Step 1: Verify NTFS Permissions on the Data Directory
- Navigate to the Memory-Optimized Filegroup directory, typically located at
C:\Program Files\Microsoft SQL Server\MSSQL17.MSSQLSERVER\MSSQL\Data\XTP\. - Right-click the folder, select Properties > Security, and confirm the SQL Server service account (e.g.,
NT Service\MSSQLSERVER) has Full Control. - If permissions are missing, click Edit, add the service account, and grant Full Control recursively to all subfolders.
Step 2: Check for File Locks from Antivirus or Backup Agents
- Open Task Manager or Resource Monitor and search for processes holding handles on the
XTPdirectory. - Temporarily disable real-time antivirus scanning on the SQL data directories, or add an exclusion rule:
Add-MpPreference -ExclusionPath "C:\Program Files\Microsoft SQL Server\MSSQL17.MSSQLSERVER\MSSQL\Data\XTP\"- Restart the SQL Server service and retry the operation that triggered the truncation.
Step 3: Run a Consistency Check and Clear Orphaned Checkpoint Files
- Execute
DBCC CHECKDBon the affected database to rule out internal corruption: DBCC CHECKDB ('YourDatabaseName') WITH NO_INFOMSGS, ALL_ERRORMSGS;- If orphaned
.bin/.chkfiles remain from a crashed session, stop the SQL Server service, manually archive the orphaned files to a backup location, and restart the service to let SQL Server rebuild the checkpoint structure.
Step 4: Validate the Underlying Disk/Volume Health
- Run
chkdsk C: /f /r(replaceC:with the actual volume) during a maintenance window to repair file system-level errors. - Reboot Windows Server 2025 if prompted, and monitor the SQL Server error log for recurrence of Error 5512 after restart.
Alternative or Verification Steps
- After applying fixes, run
ALTER DATABASE YourDatabaseName SET FILESTREAM (DIRECTORY_NAME = '')or trigger a manual checkpoint viaCHECKPOINT;to confirm the truncation completes without error. - If the issue persists, drop and recreate the Memory-Optimized Filegroup on a different volume with verified NTFS permissions, then restore data from the last known good backup.