Sql-Server

還原到 SQL Server 2017 後 DBCC CHECKDB 失敗

  • June 25, 2019

我在 SQL Server 2014 上有一個數據庫,在 SQL Server 2017 上恢復備份後,在執行 CHECKDB 時出現完整性檢查錯誤。當我在另一台使用 SQL Server 2014 的機器上恢復它時,它可以在沒有 CHECKDB 報告錯誤的情況下工作。我需要將數據庫遷移到更新的伺服器,所以我仍然可以更新我認為合適的內容。

CHECKDB 錯誤:

Msg 8948, Level 16, State 6, Line 5
Database error: Page (1:1737) is marked with the wrong type in PFS page (1:1). PFS status 0x40 expected 0x60.
Msg 8948, Level 16, State 6, Line 5
Database error: Page (1:1738) is marked with the wrong type in PFS page (1:1). PFS status 0x40 expected 0x60.
Msg 8948, Level 16, State 6, Line 5
Database error: Page (1:1739) is marked with the wrong type in PFS page (1:1). PFS status 0x40 expected 0x60.
Msg 8948, Level 16, State 6, Line 5
Database error: Page (1:1740) is marked with the wrong type in PFS page (1:1). PFS status 0x40 expected 0x60.
Msg 8948, Level 16, State 6, Line 5
Database error: Page (1:1741) is marked with the wrong type in PFS page (1:1). PFS status 0x40 expected 0x60.
Msg 8948, Level 16, State 6, Line 5
Database error: Page (1:1742) is marked with the wrong type in PFS page (1:1). PFS status 0x40 expected 0x60.
Msg 8948, Level 16, State 6, Line 5
Database error: Page (1:1743) is marked with the wrong type in PFS page (1:1). PFS status 0x40 expected 0x60.
CHECKDB found 7 allocation errors and 0 consistency errors not associated with any single object.
CHECKDB found 7 allocation errors and 0 consistency errors in database 'DBNAME'.
repair_allow_data_loss is the minimum repair level for the errors found by DBCC CHECKDB (DBNAME).

錯誤表視圖

您可以通過執行找出這些頁面屬於哪些對象:

SELECT s.name, o.name, a.index_id
FROM sys.schemas AS s
INNER JOIN sys.objects AS o
ON s.[schema_id] = o.[schema_id]
CROSS APPLY sys.dm_db_database_page_allocations
 (DB_ID(N'DBNAME'),o.[object_id],NULL,NULL,N'LIMITED') AS a
WHERE allocated_page_page_id BETWEEN 1737 AND 1743;

您可以嘗試重建該索引(或如果 index_id 為 0 或 null 的表),以查看是否可以解決分配問題。如果仍然存在,您可以嘗試刪除索引並重新創建它,或者,如果它是表或堆,則將所有內容選擇到新表中,在那裡創建新索引,刪除舊表並重命名新表.

如果這沒有幫助,您可以檢查這些頁面的內容,並確定在升級過程中失去數據是否可以接受(或者,如果不是,則不升級)。

DBCC TRACEON(3604,-1);
DBCC PAGE(N'DBNAME', 1, 1737, 2);
DBCC PAGE(N'DBNAME', 1, 1738, 2);
DBCC PAGE(N'DBNAME', 1, 1739, 2);
...

如果這是可以接受的損失,那麼您可以按照建議使用允許數據失去執行修復(在修復之前保留備份副本可能是明智的,以防您需要以某種方式從這些頁面中提取數據)。

引用自:https://dba.stackexchange.com/questions/209388