{"id":83480,"date":"2019-02-26T23:12:15","date_gmt":"2019-02-26T23:12:15","guid":{"rendered":"https:\/\/www.red-gate.com\/simple-talk\/?p=83480"},"modified":"2019-08-15T13:44:28","modified_gmt":"2019-08-15T13:44:28","slug":"identifying-page-information-in-sql-server-2019","status":"publish","type":"post","link":"https:\/\/www.red-gate.com\/simple-talk\/blogs\/identifying-page-information-in-sql-server-2019\/","title":{"rendered":"Identifying Page Information in SQL Server 2019"},"content":{"rendered":"<p>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\u00a0in the database.<\/p>\n<p>However, how to translate this information to get a database and object name?<\/p>\n<p>The image below is an example of information included in an <strong>XML_DEADLOCK_REPORT<\/strong>, only as an example. We can face information like this in other administrative tasks as well. How to translate this?<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-83481\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2019\/02\/deadlockReport.png\" alt=\"deadlock report\" width=\"586\" height=\"60\" \/><\/p>\n<p>SQL Server 2019 brings the new function <strong>sys.dm_db_page_info<\/strong> that allow us to recover page information.<\/p>\n<p>Take a look on this example:<\/p>\n<div style=\"padding-left: 30px\"><span style=\"font-family: Courier New;font-size: 10pt\"> <span style=\"color: blue\">select<\/span>\u00a0<span style=\"color: fuchsia\"><i>objecT_name<\/i><\/span><span style=\"color: maroon\">(<\/span><span style=\"color: maroon\">objecT_id<\/span><span style=\"color: maroon\">)<\/span><span style=\"color: silver\">,<\/span><span style=\"color: silver\">*<\/span>\u00a0<span style=\"color: blue\">from<\/span>\u00a0<span style=\"color: maroon\">sys<\/span><span style=\"color: silver\">.<\/span><span style=\"color: #ff0080\"><b>dm_db_page_info<\/b><\/span><span style=\"color: maroon\">(<\/span><span style=\"color: black\">9<\/span><span style=\"color: silver\">,<\/span><span style=\"color: black\">1<\/span><span style=\"color: silver\">,<\/span><span style=\"color: black\">392<\/span><span style=\"color: silver\">,<\/span><span style=\"color: red\">&#8216;DETAILED&#8217;<\/span><span style=\"color: maroon\">)<\/span> <\/span><\/div>\n<p>Using <strong>sys.dm_db_page_info<\/strong> we can identify even the object which own the page.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-83482\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2019\/02\/PageInfo.png\" alt=\"PageInfo\" width=\"1036\" height=\"70\" \/><\/p>\n<p>SQL Server 2019 goes even beyond: <strong>sys.dm_exec_requests<\/strong> has a new field called <strong>page_resource<\/strong> with the binary identification of the page when the request is waiting\/blocked by a page.<\/p>\n<p>However, this identification is not on the format for the <strong>sys.dm_db_page_info<\/strong>, we need first to convert the format and we can do this using <strong>sys.fn_pagerescracker<\/strong><\/p>\n<p>Let&#8217;s see an example. We can create some locks to block a request and check the result.<\/p>\n<p>Execute on one query window:<\/p>\n<div style=\"padding-left: 30px\"><span style=\"font-family: Courier New;font-size: 10pt\"> <span style=\"color: blue\">BEGIN<\/span>\u00a0<span style=\"color: blue\">TRANSACTION<\/span> <br \/>\n<span style=\"color: blue\">SELECT<\/span>\u00a0<span style=\"color: silver\">*<\/span> <br \/>\n<span style=\"color: blue\">FROM<\/span>\u00a0\u00a0\u00a0<span style=\"color: maroon\">customers<\/span>\u00a0<span style=\"color: blue\">WITH<\/span>\u00a0<span style=\"color: maroon\">(<\/span><span style=\"color: maroon\">updlock<\/span><span style=\"color: silver\">,<\/span>\u00a0<span style=\"color: maroon\">paglock<\/span><span style=\"color: maroon\">)<\/span>\u00a0 <\/span><\/div>\n<p>Execute on another query window:<\/p>\n<div style=\"padding-left: 30px\"><span style=\"font-family: Courier New;font-size: 10pt\"> <span style=\"color: blue\">BEGIN<\/span>\u00a0<span style=\"color: blue\">TRANSACTION<\/span> <br \/>\n<span style=\"color: blue\">SELECT<\/span>\u00a0<span style=\"color: silver\">*<\/span> <br \/>\n<span style=\"color: blue\">FROM<\/span>\u00a0\u00a0\u00a0<span style=\"color: maroon\">orders<\/span>\u00a0<span style=\"color: blue\">WITH<\/span>\u00a0<span style=\"color: maroon\">(<\/span><span style=\"color: maroon\">updlock<\/span><span style=\"color: silver\">,<\/span>\u00a0<span style=\"color: maroon\">paglock<\/span><span style=\"color: maroon\">)<\/span> <br \/>\n<span style=\"color: blue\">SELECT<\/span>\u00a0<span style=\"color: silver\">*<\/span> <br \/>\n<span style=\"color: blue\">FROM<\/span>\u00a0\u00a0\u00a0<span style=\"color: maroon\">customers<\/span>\u00a0<span style=\"color: blue\">WITH<\/span>\u00a0<span style=\"color: maroon\">(<\/span><span style=\"color: maroon\">updlock<\/span><span style=\"color: silver\">,<\/span>\u00a0<span style=\"color: maroon\">paglock<\/span><span style=\"color: maroon\">)<\/span>\u00a0 <\/span><\/div>\n<p>\nThe 2nd query window will be blocked by the customers lock on the first query window. The <strong>PAGLOCK<\/strong> hint forces the lock to be taken on the entire page only for this example, it&#8217;s not something to be used in production.<\/p>\n<p>Use this query on a 3rd query window to confirm we have a request waiting for a page:<\/p>\n<div style=\"padding-left: 30px\"><span style=\"font-family: Courier New;font-size: 10pt\"> <span style=\"color: blue\">SELECT<\/span>\u00a0<span style=\"color: maroon\">session_id<\/span><span style=\"color: silver\">,<\/span> <br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<span style=\"color: maroon\">request_id<\/span><span style=\"color: silver\">,<\/span> <br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<span style=\"color: maroon\">page_resource<\/span> <br \/>\n<span style=\"color: blue\">FROM<\/span>\u00a0\u00a0\u00a0<span style=\"color: maroon\">sys<\/span><span style=\"color: silver\">.<\/span><span style=\"color: maroon\">dm_exec_requests<\/span> <br \/>\n<span style=\"color: blue\">WHERE<\/span>\u00a0\u00a0<span style=\"color: maroon\">page_resource<\/span>\u00a0<span style=\"color: blue\">IS<\/span>\u00a0<span style=\"color: blue\">NOT<\/span>\u00a0<span style=\"color: blue\">NULL<\/span>\u00a0 <\/span><\/div>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-83483\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2019\/02\/PageResource.png\" alt=\"Page Resource\" width=\"312\" height=\"64\" \/><\/p>\n<p>Now we can use the two other functions to identify the information about the page, including the object name:<\/p>\n<div style=\"padding-left: 30px\"><span style=\"font-family: Courier New;font-size: 10pt\"> <span style=\"color: blue\">SELECT<\/span>\u00a0<span style=\"color: fuchsia;font-style: italic\">Object_name<\/span><span style=\"color: maroon\">(<\/span><span style=\"color: maroon\">page_info<\/span><span style=\"color: silver\">.<\/span><span style=\"color: maroon\">object_id<\/span><span style=\"color: maroon\">)<\/span>\u00a0<span style=\"color: blue\">AS<\/span>\u00a0<span style=\"color: maroon\">object_name,page_info<span style=\"color: silver\">.<\/span><span style=\"color: silver\">*<\/span><\/span>\u00a0<br \/>\n<span style=\"color: blue\">FROM<\/span>\u00a0\u00a0\u00a0<span style=\"color: maroon\">sys<\/span><span style=\"color: silver\">.<\/span><span style=\"color: maroon\">dm_exec_requests<\/span>\u00a0<span style=\"color: blue\">AS<\/span>\u00a0<span style=\"color: maroon\">d<\/span> <br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<span style=\"color: blue\">CROSS<\/span>\u00a0<span style=\"color: maroon\">apply<\/span>\u00a0<span style=\"color: maroon\">sys<\/span><span style=\"color: silver\">.<\/span><span style=\"color: #ff0080;font-weight: bold\">Fn_pagerescracker<\/span><span style=\"color: maroon\">(<\/span><span style=\"color: maroon\">d<\/span><span style=\"color: silver\">.<\/span><span style=\"color: maroon\">page_resource<\/span><span style=\"color: maroon\">)<\/span>\u00a0<span style=\"color: blue\">AS<\/span>\u00a0<span style=\"color: maroon\">r<\/span> <br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<span style=\"color: blue\">CROSS<\/span>\u00a0<span style=\"color: maroon\">apply<\/span> <br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<span style=\"color: maroon\">sys<\/span><span style=\"color: silver\">.<\/span><span style=\"color: #ff0080;font-weight: bold\">Dm_db_page_info<\/span><span style=\"color: maroon\">(<\/span><span style=\"color: maroon\">r<\/span><span style=\"color: silver\">.<\/span><span style=\"color: maroon\">db_id<\/span><span style=\"color: silver\">,<\/span>\u00a0<span style=\"color: maroon\">r<\/span><span style=\"color: silver\">.<\/span><span style=\"color: maroon\">file_id<\/span><span style=\"color: silver\">,<\/span>\u00a0<span style=\"color: maroon\">r<\/span><span style=\"color: silver\">.<\/span><span style=\"color: maroon\">page_id<\/span><span style=\"color: silver\">,<\/span>\u00a0<span style=\"color: red\">&#8216;DETAILED&#8217;<\/span><span style=\"color: maroon\">)<\/span>\u00a0<span style=\"color: blue\">AS<\/span> <br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<span style=\"color: maroon\">page_info<\/span> <br \/>\n<span style=\"color: blue\">WHERE<\/span>\u00a0\u00a0<span style=\"color: maroon\">d<\/span><span style=\"color: silver\">.<\/span><span style=\"color: maroon\">page_resource<\/span>\u00a0<span style=\"color: blue\">IS<\/span>\u00a0<span style=\"color: blue\">NOT<\/span>\u00a0<span style=\"color: blue\">NULL<\/span>\u00a0<\/span><\/div>\n<div>\u00a0<\/div>\n<div><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-83484\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2019\/02\/dmRequestPageInfo.png\" alt=\"dmrequest pageinfo\" width=\"1014\" height=\"67\" \/><\/div>\n<div>\u00a0<\/div>\n<h4>References<\/h4>\n<div style=\"padding-left: 30px\"><a href=\"https:\/\/docs.microsoft.com\/en-us\/sql\/relational-databases\/system-functions\/sys-fn-pagerescracker-transact-sql?view=sql-server-2017\">sys.fn_PageResCraker<\/a><\/div>\n<div style=\"padding-left: 30px\"><a href=\"https:\/\/docs.microsoft.com\/en-us\/sql\/relational-databases\/system-dynamic-management-views\/sys-dm-db-page-info-transact-sql?view=sqlallproducts-allversions\">sys.dm_db_page_info<\/a><\/div>\n<div>\u00a0<\/div>\n","protected":false},"excerpt":{"rendered":"<p>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\u00a0in the database. However, how to translate this information to get a database and object name? The image below is an example of&#8230;&hellip;<\/p>\n","protected":false},"author":50808,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[2],"tags":[4170],"coauthors":[6810],"class_list":["post-83480","post","type-post","status-publish","format-standard","hentry","category-blogs","tag-database-administration"],"acf":[],"_links":{"self":[{"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/posts\/83480","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/users\/50808"}],"replies":[{"embeddable":true,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/comments?post=83480"}],"version-history":[{"count":1,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/posts\/83480\/revisions"}],"predecessor-version":[{"id":83485,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/posts\/83480\/revisions\/83485"}],"wp:attachment":[{"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/media?parent=83480"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/categories?post=83480"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/tags?post=83480"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/coauthors?post=83480"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}