其實本篇文章算是翻譯Finding a table name from a page ID這篇文章,只是不想直接翻譯。用本身的理解敘說出來。算是對上一篇博客"SQL Server如何找出一個表包含的頁信息(Page)"的承前啓後。html
咱們若是從日誌或dump文件中發現頁信息,那麼可否經過頁信息找到其關聯的對象呢? 答案是能夠,並且很是簡單。以下所示,這個DBCC PAGE的輸出信息:sql
DBCC execution completed. If DBCC printed error messages, contact your system administrator.
PAGE: (1:24188)
BUFFER:
BUF @0x000000018123EDC0
bpage = 0x000000012AAD6000 bhash = 0x0000000000000000 bpageno = (1:24188)
bdbid = 7 breferences = 0 bcputicks = 0
bsampleCount = 0 bUse1 = 26077 bstat = 0x9
blog = 0x21cc7a7a bnext = 0x0000000000000000
PAGE HEADER:
Page @0x000000012AAD6000
m_pageId = (1:24188) m_headerVersion = 1 m_type = 1
m_typeFlagBits = 0x0 m_level = 0 m_flagBits = 0x8200
m_objId (AllocUnitId.idObj) = 439 m_indexId (AllocUnitId.idInd) = 256
Metadata: AllocUnitId = 72057594066698240
Metadata: PartitionId = 72057594059030528 Metadata: IndexId = 0
Metadata: ObjectId = 631673298 m_prevPage = (0:0) m_nextPage = (0:0)
pminlen = 8 m_slotCnt = 193 m_freeCnt = 376
m_freeData = 7430 m_reservedCnt = 0 m_lsn = (47:211:2)
m_xactReserved = 0 m_xdesId = (0:0) m_ghostRecCnt = 0
m_tornBits = 1650828474 DB Frag ID = 1
Allocation Status
.....................................................................
輸出信息裏面有很重要的一部分信息(PAGE HEADER),如上圖所示:數據庫
經過Metadata : ObjectId =631673298, 咱們能夠找出這個Page所涉及的對象爲TestDeadLock(其實這個Page ID確實是從表TestDeadLock中找出的一個Page)app
IndexId =0 就能夠判斷這個是數據頁,不是索引頁(Index Page), m_type = 1就表示它是Data Page,m_level = 0 就表示頁的層數爲0spa
其實DBCC PAGE的輸出信息裏面能夠挖掘到不少信息,就看你的貯備的知識多少和你是否對這些信息感興趣。翻譯
Paul S. Randal的博客中提到,若是ObjectId爲99,那麼意味着這個頁面已經損壞,你須要等待DBCC CHECKDB完成才能知道損壞的程度; 若是您看到ObjectId爲0,則表示未找到對應的元數據。這多是由於:3d
自記錄頁面損壞以來,已刪除該頁面所屬的表日誌
系統目錄以某種方式損壞了code
該頁面已損壞,所以使用了不正確的值來查找元數據orm
不管如何,您都須要等待DBCC CHECKDB完成才能知道區損壞的程度。
另外,若是OBJECT_NAME (xxxx)返回NULL,要麼是你執行腳本上下文的數據庫弄錯了,要麼是元數據損壞了。須要DBCC CHECKDB返回詳細信息。
The Metadata: ObjectId field is what we want. If you see it is 99, then stop as that means the damaged page is part of the allocation system and not part of a table and you’ll need to wait for DBCC CHECKDB to complete to know the extent of the damage.
If you see the ObjectId is 0, that means there was no metadata found. This could be because:
The table that the page was part of has been deleted since the page corruption was logged
The system catalogs are corrupt in some way
The page is corrupt and so incorrect values were used to look up the metadata
In any case, you’ll need to wait for DBCC CHECKDB to complete to know the extent of the damage.
參考資料:
https://www.sqlskills.com/blogs/paul/finding-table-name-page-id/