Identifying Page Information in SQL Server 2019

Comments 0

Share to social media

SQL Server 2019 has some new and very interesting functions to identify information about pages. Many operations, such as analyzing current activities, locks or deadlocks, may result in some metadata pointing/blaming one page in the database.

However, how to translate this information to get a database and object name?

The image below is an example of information included in an XML_DEADLOCK_REPORT, only as an example. We can face information like this in other administrative tasks as well. How to translate this?

deadlock report

SQL Server 2019 brings the new function sys.dm_db_page_info that allow us to recover page information.

Take a look on this example:

select objecT_name(objecT_id),* from sys.dm_db_page_info(9,1,392,‘DETAILED’)

Using sys.dm_db_page_info we can identify even the object which own the page.

PageInfo

SQL Server 2019 goes even beyond: sys.dm_exec_requests has a new field called page_resource with the binary identification of the page when the request is waiting/blocked by a page.

However, this identification is not on the format for the sys.dm_db_page_info, we need first to convert the format and we can do this using sys.fn_pagerescracker

Let’s see an example. We can create some locks to block a request and check the result.

Execute on one query window:

BEGIN TRANSACTION
SELECT *
FROM   customers WITH (updlock, paglock) 

Execute on another query window:

BEGIN TRANSACTION
SELECT *
FROM   orders WITH (updlock, paglock)
SELECT *
FROM   customers WITH (updlock, paglock) 

The 2nd query window will be blocked by the customers lock on the first query window. The PAGLOCK hint forces the lock to be taken on the entire page only for this example, it’s not something to be used in production.

Use this query on a 3rd query window to confirm we have a request waiting for a page:

SELECT session_id,
       request_id,
       page_resource
FROM   sys.dm_exec_requests
WHERE  page_resource IS NOT NULL 

Page Resource

Now we can use the two other functions to identify the information about the page, including the object name:

SELECT Object_name(page_info.object_id) AS object_name,page_info.* 
FROM   sys.dm_exec_requests AS d
       CROSS apply sys.Fn_pagerescracker(d.page_resource) AS r
       CROSS apply
       sys.Dm_db_page_info(r.db_id, r.file_id, r.page_id, ‘DETAILED’) AS
       page_info
WHERE  d.page_resource IS NOT NULL 
 
dmrequest pageinfo
 

References

sys.fn_PageResCraker
sys.dm_db_page_info
 

Article tags

Load comments

About the author

Dennes Torres

See Profile

Dennes Torres is a Data Platform MVP and Software Architect living in Malta who loves SQL Server and software development and has more than 20 years of experience. Dennes can improve Data Platform Architectures and transform data in knowledge. He moved to Malta after more than 10 years leading devSQL PASS Chapter in Rio de Janeiro and now is a member of the leadership team of MMDPUG PASS Chapter in Malta organizing meetings, events, and webcasts about SQL Server. He is an MCT, MCSE in Data Platforms and BI, with more titles in software development. You can get in touch on his blog https://dennestorres.com or at his work https://dtowersoftware.com