SQL Server如何通過Page_ID找到對應的表


其實本篇文章算是翻譯Finding a table name from a page ID這篇文章,只是不想直接翻譯。用自己的理解敘說出來。算是對上一篇博客"SQL Server如何找出一個表包含的頁信息(Page)"的承前啟后。

 

我們如果從日志或dump文件中發現頁信息,那么能否通過頁信息找到其關聯的對象呢? 答案是可以,而且非常簡單。如下所示,這個DBCC PAGE的輸出信息:

 

 

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

 

clip_image001

 

 

輸出信息里面有很重要的一部分信息(PAGE HEADER),如上圖所示:

 

通過Metadata : ObjectId =631673298, 我們可以找出這個Page所涉及的對象為TestDeadLock(其實這個Page ID確實是從表TestDeadLock中找出的一個Page)

 

IndexId =0 就可以判斷這個是數據頁,不是索引頁(Index Page), m_type = 1就表示它是Data Page,m_level = 0 就表示頁的層數為0

 

其實DBCC PAGE的輸出信息里面可以挖掘到很多信息,就看你的貯備的知識多少和你是否對這些信息感興趣。

 

 

clip_image002

 

Paul S. Randal的博客中提到,如果ObjectId為99,那么意味着這個頁面已經損壞,你需要等待DBCC CHECKDB完成才能知道損壞的程度; 如果您看到ObjectId為0,則表示未找到對應的元數據。這可能是因為:

 

自記錄頁面損壞以來,已刪除該頁面所屬的表

系統目錄以某種方式損壞了

該頁面已損壞,因此使用了不正確的值來查找元數據

無論如何,您都需要等待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/


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM