總結
本文提供解決因系統磁碟扇區大小超過支援 4 KB 所導致的 SQL Server 安裝與啟動失敗的解決方案。 這些錯誤發生在現代儲存裝置,如 NVMe 固態硬碟(SSD)報告系統磁碟扇區大小超過 4 KB 時。 症狀包括 SQL 設定失敗、錯誤 5178 和 5179、資料庫引擎 啟動或恢復處理失敗、「日誌 IO 錯位」警告,以及ntdll.dll應用程式錯誤。 這些解決方案適用於所有已發佈的 SQL Server 版本,包括 LocalDB。
在系統磁碟扇區大小大於 4 KB 的機器上安裝 SQL Server,可能導致以下情境。
案例 1:將檔案移至具有相容扇區大小的磁碟區
當你嘗試使用扇區大小大於 4 KB 時,會出現以下錯誤訊息:
Error: 5179, Severity: 16, State: 1.
Cannot use file 'data file path', because it is on a volume with sector size 8192. SQL Server supports a maximum sector size of 4096 bytes. Move the file to a volume with a compatible sector size.
案例 2:找不到資料庫引擎啟動句柄
當你嘗試在執行 Windows 的 Azure 虛擬機(VM)上安裝 SQL Server 實例時,安裝失敗,並在安裝過程中引擎嘗試啟動時,會在 SQL Server 錯誤日誌中彈出以下錯誤訊息:
無法使用檔案 『...\master.mdf』,因為它原本是以扇區大小 4096 格式化,現在位於扇區大小為 8192 的磁碟區上。 請將檔案移至與原來磁區大小相同或較小的磁碟區上。
此外,您可以在 SQL Server 安裝程式資料夾中Summary.txt記錄檔中看到下列資訊:
Detailed results:
Feature: Database Engine Services
Status: Failed
Reason for failure: An error occurred during the setup process of the feature.
Next Step: Use the following information to resolve the error, uninstall this feature, and then run the setup process again.
Component name: SQL Server Database Engine Services Instance Features
Component error code: 0x851A0019
Error description: Could not find the Database Engine startup handle.
如需詳細資訊,請參閱 SQL Server 安裝失敗,並在 Windows Server 2022 Azure 虛擬機上發生扇區大小錯誤。
案例 3:等待資料庫引擎復原控制碼失敗
當你安裝任何版本的 SQL Server 時,你會看到 SQL Server 的 資料庫引擎 Services 元件出現以下錯誤:
Feature: Database Engine Services
Status: Failed
Reason for failure: An error occurred during the setup process of the feature.
Next Step: Use the following information to resolve the error, uninstall this feature, and then run the setup process again.
Component name: SQL Server Database Engine Services Instance Features
Component error code: 0x851A001A
Error description: Wait on the Database Engine recovery handle failed. Check the SQL Server error log for potential causes.
或者,您會在 SQL Server 錯誤記錄檔中看到下列錯誤:
2025-02-26 20:01:16.79 spid14s Starting up database 'master'.
2025-02-26 20:01:16.80 spid14s Error: 5178, Severity: 16, State: 1.
2025-02-26 20:01:16.80 spid14s Cannot use file 'C:\Program Files\Microsoft SQL Server\MSSQL16.MSSQLSERVER\MSSQL\DATA\master.mdf' because it was originally formatted with sector size 4096 and is now on a volume with sector size 8192. Move the file to a volume with a sector size that is the same as or smaller than the original sector size.
案例 4:有 256 個未對齊的記錄 IO 需要回復到同步 IO
您可以在 Windows 10 裝置上安裝任何版本的 SQL Server。 然後,您將裝置上的作系統 (OS) 升級至 Windows 11。 當您嘗試在 Windows 11 裝置上啟動 SQL Server 時,服務無法啟動。 在 SQL Server 錯誤記錄檔中,您會注意到下列項目:
2021-11-05 23:42:47.14 spid9s There have been 256 misaligned log IOs which required falling back to synchronous IO. The current IO is on file C:\Program Files\Microsoft SQL Server\MSSQL15.MSSQLSERVER\MSSQL\DATA\master.mdf.
案例 5:來自 ntdll.dll 的 SQL Server 應用程式錯誤
您可以在 Windows 10 裝置上安裝任何版本的 SQL Server。 然後,您會將裝置上的OS升級至 Windows 11。 當您嘗試在 Windows 11 裝置上啟動 SQL Server 時,服務無法啟動。 在 SQL Server 錯誤記錄檔中,您會注意到下列項目:
Faulting application name: sqlservr.exe, version: 2019.150.2000.5, time stamp: 0x5d8a9215
Faulting module name: ntdll.dll, version: 10.0.22000.120, time stamp: 0x50702a8c
Exception code: 0xc0000005
Fault offset: 0x00000000000357ae
Faulting process id: 0x1124
Faulting application start time: 0x01d7bf67449d262c
Faulting application path: C:\Program Files\Microsoft SQL Server\MSSQL15.MSSQLSERVER\MSSQL\Binn\sqlservr.exe
Faulting module path: C:\Windows\SYSTEM32\ntdll.dll
案例 6:將檔案移至扇區大小與原始扇區大小相同或小於原始扇區大小的磁碟區
您在 Windows 11 裝置上安裝 LocalDB,安裝程式會失敗。 在 SQL Server 錯誤記錄檔中,您會注意到下列項目:
2021-12-15 23:25:04.28 spid5s Cannot use file 'C:\Users\Administrator\AppData\Local\Microsoft\Microsoft SQL Server Local DB\Instances\TestInstance\master.mdf' because it was originally formatted with sector size 4096 and is now on a volume with sector size 16384. Move the file to a volume with a sector size that is the same as or smaller than the original sector size.
在 Windows 11 裝置的 Windows 應用程式事件日誌中,你會注意到以下條目:
Message : Windows API call WaitForMultipleObjects returned error code: 575. Windows system error message is: {Application Error}
The application was unable to start correctly (0x%lx). Click OK to close the application.
Reported at line: 3621.
Source : SQLLocalDB 11.0
注意事項
針對您手動安裝的 SQL Server 實例,或應用程式所安裝的 LocalDB 實例,您可能會遇到先前案例中所提及的失敗。
SQL Server 中磁碟磁區大小錯誤的原因
在服務啟動期間,SQL Server 會開始資料庫復原程式,以確保資料庫一致性。 在嘗試開啟系統和使用者資料庫檔案之前,該資料庫復原過程的一部分涉及對底層檔案系統進行一致性檢查。
某些新的儲存設備和設備驅動器顯示的磁碟扇區大小大於支援的 4-KB 扇區大小。
發生此問題時,由於不支援的文件系統,SQL Server 無法啟動,因為 SQL Server 目前支援 512 位元組和 4 KB 的磁區記憶體大小。
您可以執行 命令來確認您遇到此特定問題:
fsutil fsinfo sectorinfo <volume pathname>
例如,若要分析 E: 磁碟區,請執行下列命令:
fsutil fsinfo sectorinfo E:
尋找以位元組為單位傳回的值 PhysicalBytesPerSectorForAtomicity 和 PhysicalBytesPerSectorForPerformance。 如果不同,保留 最大的 那個以判斷磁碟扇區大小。 值為 4096 表示磁區記憶體大小為 4 KB。
此外,請參考 Microsoft 對 Windows 中 4-KB 扇區硬碟的支援政策。
注意事項
沒有發行版本的 SQL Server 與大於 4 KB 的扇區大小相容。 欲了解更多資訊,請參閱 SQL Server 中的硬碟扇區大小支援邊界。
SQL Server 中磁碟磁區大小錯誤的解決步驟
目前,若使用提供大於 4 KB 扇區大小的新式儲存平台,例如 NVMe,需要
ForcedPhysicalSectorSizeInBytes登錄機碼才能成功安裝 SQL Server。 此 Windows 作業系統的登錄機碼會將扇區大小強制模擬為 4 KB。若要新增
ForcedPhysicalSectorSizeInBytes登錄機碼,請使用註冊表編輯器,或依照命令提示字元或PowerShell 一節中的說明執行命令。 此案例不需要新增追蹤旗標 1800。重要
本節包含的步驟會告訴您如何修改 Windows 登錄。 然而,不當修改登錄可能會發生嚴重的問題。 因此,請務必小心執行下列步驟。 為增加保護起見,請先備份登錄,再進行修改。 如此一來,您就可以在發生問題時還原登錄。 如需如何備份和還原登錄的詳細資訊,請參閱 如何在 Windows 中備份和還原登錄一文。
- 以系統管理員身分執行註冊表編輯器。
- 瀏覽至
Computer\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\stornvme\Parameters\Device。 - 選擇 編輯>新的>多重字串值,並將其命名為
ForcedPhysicalSectorSizeInBytes。 - 以滑鼠右鍵按下名稱,選取 [修改],然後在 [
* 4095] 字段中輸入 。 - 選取 [ 確定 ],然後關閉 [註冊表編輯器]。
您必須在新增登錄機碼之後重新啟動裝置,此變更才會生效。
如果您未新增登錄機碼,而且在此系統上有多個磁碟驅動器,您可以在安裝 SQL Server 完成之後,為資料庫檔案指定不同的位置。 請確定磁碟驅動器會在查詢
fsutil命令時反映支援的扇區大小。 SQL Server 目前支援 512 個字節和 4,096 個字節的扇區記憶體大小。
謹慎
如果你已經建立了一個儲存池,裡面有扇區大小超過 4 KB 的磁碟來存放 SQL Server 檔案,你必須先移除儲存池,套用本文提到的故障排除方法,然後重建儲存池,然後再嘗試在該儲存池上安裝 SQL Server。
其他相關資訊
Windows 11 原生 NVMe 驅動程式已更新,以包含 NVMe 儲存裝置直接回報的實際扇區大小。 這樣做是為了而非依賴從文件系統驅動程式模擬的資訊。
Windows 10 驅動程式不會回報實體儲存的來源扇區大小。
改良版的 Windows 11 驅動程式忽略了常見 NVMe 儲存裝置所使用的模擬功能。 例如, fsutil 顯示扇區大小 8 KB 或 16 KB,而不是模擬 Windows 所需的 4 KB 扇區大小。
下表提供各作業系統所報告的扇區大小的比較。 此範例說明使用相同儲存裝置的 Windows 10 與 Windows 11 之間的差異。 針對PhysicalBytesPerSectorForAtomicity和PhysicalBytesPerSectorForPerformance的值,Windows 10 顯示 4 KB,而 Windows 11 顯示 16 KB。
的範例輸出 fsutil fsinfo sectorinfo <volume pathname>
| Windows 10 | Windows 11 |
|---|---|
LogicalBytesPerSector : 512 |
LogicalBytesPerSector : 512 |
PhysicalBytesPerSectorForAtomicity : 4096 |
PhysicalBytesPerSectorForAtomicity : 16384 |
PhysicalBytesPerSectorForPerformance : 4096 |
PhysicalBytesPerSectorForPerformance : 16384 |
FileSystemEffectivePhysicalBytesPerSectorForAtomicity : 4096 |
FileSystemEffectivePhysicalBytesPerSectorForAtomicity : 4096 |
Device Alignment : Aligned (0x000) |
Device Alignment : Aligned (0x000) |
Partition alignment on device : Aligned (0x000) |
Partition alignment on device : Aligned (0x000) |
No Seek Penalty |
No Seek Penalty |
Trim Supported |
Trim Supported |
Not DAX capable |
Not DAX capable |
Not Thinly-Provisioned |
Not Thinly-Provisioned |