Windows 11 + Samsung 980 踩坑:在 LocalDB 15.0 實例啓動期間出錯: 無法啓動 SQL Server 進程(附贈 查詢指定日期範圍內的前1000條SQL執行記錄)

Windows 11 + Samsung 980 踩坑:在 LocalDB 實例啓動期間出錯: 無法啓動 SQL Server 進程

起因

Microsoft Visual Studio 2022 連接 (localdb)\MSSQLLocalDB,等待半天沒連接成功。

幾經搜索,一頓操作猛如虎,反正數據不重要,先刪後重建:

PS C:\Users\Administrator> sqllocaldb delete MSSQLLocalDB
LocalDB instance "MSSQLLocalDB" deleted.
PS C:\Users\Administrator> sqllocaldb create MSSQLLocalDB -s
Creation of LocalDB instance "MSSQLLocalDB" failed because of the following error:
在 LocalDB 實例啓動期間出錯: 無法啓動 SQL Server 進程。

看到這個新的錯誤,我懵了。
Win + R 鍵,打開運行窗口,輸入 eventvwr,打開 事件查看器
翻 Windows 事件日誌,在 Windows 日誌 ——> 應用程序 下,發現3條蛛絲馬跡:

事件ID:1000
來源:Application Error
事件數據:

錯誤應用程序名稱: sqlservr.exe,版本: 2019.150.4153.1,時間戳: 0x60f610ce
錯誤模塊名稱: ntdll.dll,版本: 10.0.22000.778,時間戳: 0x5398ab6f
異常代碼: 0xc0000005
錯誤偏移量: 0x0000000000035c7e
錯誤進程 ID: 0x1784
錯誤應用程序啓動時間: 0x01d89aaf6ee85153
錯誤應用程序路徑: C:\Program Files\Microsoft SQL Server\150\LocalDB\Binn\sqlservr.exe
錯誤模塊路徑: C:\Windows\SYSTEM32\ntdll.dll
報告 ID: c1912614-645d-48cf-903b-aa73054de47b
錯誤程序包全名: 
錯誤程序包相對應用程序 ID: 

事件ID:1001
來源:Windows Error Reporting
事件數據:

故障存儲段 ,類型 0
事件名稱: APPCRASH
響應: 不可用
Cab ID: 0

問題簽名:
P1: sqlservr.exe
P2: 2019.150.4153.1
P3: 60f610ce
P4: ntdll.dll
P5: 10.0.22000.778
P6: 5398ab6f
P7: c0000005
P8: 0000000000035c7e
P9: 
P10: 

附加文件:
\\?\C:\ProgramData\Microsoft\Windows\WER\Temp\WER.cad8ce7d-17e3-469d-be84-c89fcfc3de86.tmp.mdmp
\\?\C:\ProgramData\Microsoft\Windows\WER\Temp\WER.ac119f5e-7188-4361-ba0d-aaed83150fb8.tmp.WERInternalMetadata.xml
\\?\C:\ProgramData\Microsoft\Windows\WER\Temp\WER.685f680a-30b6-4dba-b9cb-2d621e24fcfe.tmp.xml
\\?\C:\ProgramData\Microsoft\Windows\WER\Temp\WER.c3c60740-abb8-4c04-a544-fc9711da9bfc.tmp.csv
\\?\C:\ProgramData\Microsoft\Windows\WER\Temp\WER.be8cc631-5df4-4bda-82e4-3258776b94d5.tmp.txt
\\?\C:\Users\Administrator\AppData\Local\Temp\WER.337ad876-47d6-44cc-b85a-e00a072bd446.tmp.appcompat.txt
\\?\C:\ProgramData\Microsoft\Windows\WER\ReportQueue\AppCrash_sqlservr.exe_7db2cb6f1a5bb53cb07826afa1c25735cec610_8a932130_cab_8a90fb42-c0d2-4726-8075-69ef4dfff944\memory.hdmp

可在此處獲取這些文件:
\\?\C:\ProgramData\Microsoft\Windows\WER\ReportQueue\AppCrash_sqlservr.exe_7db2cb6f1a5bb53cb07826afa1c25735cec610_8a932130_cab_8a90fb42-c0d2-4726-8075-69ef4dfff944

分析符號: 
重新檢查解決方案: 0
報告 ID: c1912614-645d-48cf-903b-aa73054de47b
報告狀態: 100
哈希存儲段: nCab GUID: 0

事件ID:528
來源:SQLLocalDB 15.0
事件數據:

Windows API 調用 WaitForMultipleObjects 返回了錯誤代碼: 575。Windows 系統錯誤消息爲: {應用程序錯誤}
應用程序無法正常啓動(0x%lx)。請單擊“確定”關閉應用程序。
,報告的行是: 3714. 

附上英文版的事件日誌

Windows Event Logs

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: 3714.

解決方案

根據最近一條錯誤事件信息,又是幾番搜索,
最終找到這一條冷門的解決方案:https://dba.stackexchange.com/questions/303823/error-starting-localdb-on-windows-11

文中提到:

Windows 11 and Windows Server 2022 do not report compatible PhysicalBytesPerSectorForAtomicity information for some SSD storage devices at this time. This causes issues with SQL Server IO when reported size is over 4K. See troubleshoot errors related to system disk sector size greater than 4 KB for additional details.

For your reference, below is example output of the command from a working (Samsung 980 PRO 2TB NVMe) and non-working (Samsung 980 1TB NVMe) system:fsutil fsinfo sectorinfo c:

Working drive:

LogicalBytesPerSector :                                 512
PhysicalBytesPerSectorForAtomicity :                    4096
PhysicalBytesPerSectorForPerformance :                  4096
FileSystemEffectivePhysicalBytesPerSectorForAtomicity : 4096

Problem drive:

LogicalBytesPerSector :                                  512
PhysicalBytesPerSectorForAtomicity :                   16384
PhysicalBytesPerSectorForPerformance :                 16384
FileSystemEffectivePhysicalBytesPerSectorForAtomicity : 4096

Does anyone have any recommendations for me to try?

Work-arounds I've seen suggested include:

  • Install SQL Server on a drive that reports correct sector information (not over 4K)
  • Create a VHD/VHDX and install SQL Server on that drive
  • Start SQL Server with trace flag 1800

The trace flag work-around is probably the easiest for your existing installation. However, it doesn't seem LocalDb provides a documented way to specify trace flags (one can use SQL Server Configuration Manager for other editions). I found this answer on SO that shows the registry location for LocalDb startup parameters and tweaked it for SQL 2019 LocalDb and trace flag 1800.

I tested these Powershell commands on my PC and it sets the LocalDB 1800 trace flag correctly.

New-Item -Path 'HKLM:\SOFTWARE\Microsoft\Microsoft SQL Server\MSSQL15E.LOCALDB\MSSQLServer\Parameters' -Force
New-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Microsoft SQL Server\MSSQL15E.LOCALDB\MSSQLServer\Parameters' -Name 'SQLArg0' -Value "-T1800" -PropertyType String -Force

You'll need to restart localDb afterwards:

sqllocaldb stop MSSQLLocalDB
sqllocaldb start MSSQLLocalDB

感言

我尼瑪,這冷門錯誤都給我碰上了!!!

附贈

有一網友微信問我:如何獲取SQL Server最近幾天執行過的SQL語句?

這裏附上查詢指定日期範圍內的前1000條SQL執行記錄:

SELECT TOP
	1000 QS.creation_time,
	SUBSTRING (
		ST.text,
		( QS.statement_start_offset / 2 ) + 1,
		(
		( CASE QS.statement_end_offset WHEN - 1 THEN DATALENGTH( ST.text ) ELSE QS.statement_end_offset END - QS.statement_start_offset ) / 2 
	) + 1 
	) AS statement_text,
	ST.text,
	QS.total_worker_time,
	QS.last_worker_time,
	QS.max_worker_time,
	QS.min_worker_time 
FROM
	sys.dm_exec_query_stats QS CROSS APPLY sys.dm_exec_sql_text ( QS.sql_handle ) ST 
WHERE
	1 = 1 
	AND QS.creation_time BETWEEN '2022-07-01 10:00:00' 
	AND '2022-07-31 23:59:59' 
	AND ST.text LIKE '%%' 
ORDER BY
	QS.creation_time DESC;
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章