Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Introducing Microsoft SQL Server 2019

You're reading from   Introducing Microsoft SQL Server 2019 Reliability, scalability, and security both on premises and in the cloud

Arrow left icon
Product type Paperback
Published in Apr 2020
Publisher Packt
ISBN-13 9781838826215
Length 488 pages
Edition 1st Edition
Languages
Arrow right icon
Authors (8):
Arrow left icon
Allan Hirt Allan Hirt
Author Profile Icon Allan Hirt
Allan Hirt
Dustin Ryan Dustin Ryan
Author Profile Icon Dustin Ryan
Dustin Ryan
Mitchell Pearson Mitchell Pearson
Author Profile Icon Mitchell Pearson
Mitchell Pearson
Kellyn Gorman Kellyn Gorman
Author Profile Icon Kellyn Gorman
Kellyn Gorman
Dave Noderer Dave Noderer
Author Profile Icon Dave Noderer
Dave Noderer
Buck Woody Buck Woody
Author Profile Icon Buck Woody
Buck Woody
Arun Sirpal Arun Sirpal
Author Profile Icon Arun Sirpal
Arun Sirpal
James Rowland-Jones James Rowland-Jones
Author Profile Icon James Rowland-Jones
James Rowland-Jones
+4 more Show less
Arrow right icon
View More author details
Toc

Table of Contents (15) Chapters Close

Preface 1. Optimizing for performance, scalability and real‑time insights 2. Enterprise Security FREE CHAPTER 3. High Availability and Disaster Recovery 4. Hybrid Features – SQL Server and Microsoft Azure 5. SQL Server 2019 on Linux 6. SQL Server 2019 in Containers and Kubernetes 7. Data Virtualization 8. Machine Learning Services Extensibility Framework 9. SQL Server 2019 Big Data Clusters 10. Enhancing the Developer Experience 11. Data Warehousing 12. Analysis Services 13. Power BI Report Server 14. Modernization to the Azure Cloud

Troubleshooting page resource waits

A new and exciting feature in SQL Server 2019 is sys.dm_db_page_info. This new dynamic management function (DMF) retrieves useful page information, such as page_id, file_id, index_id, object_id, and page_type, that can be used for troubleshooting and debugging performance issues in SQL Server. Historically, troubleshooting has involved the use of DBCC Page and the undocumented DMF sys.dm_db_page_allocations.

Unlike DBCC Page, which provides the entire contents of a page, sys.dm_db_page_info only returns header information about pages. Fortunately, this will be sufficient for most troubleshooting and performance tuning scenarios.

This section will discuss the following topics:

  • Database State permissions
  • sys.dm_db_page_info parameters
  • New column page_resource in (sys.dm_exec_requests, sys.processes)
  • sys.fn_PageResCracker

sys.dm_db_page_info

First, to leverage this new DMF, we require the VIEW DATABASE STATE permission. The following code can be used to provide access:

GRANT VIEW DATABASE STATE TO [login]

There are four required parameters:

sys.dm_db_page_info ( DatabaseId, FileId, PageId, Mode )

The following argument descriptions are provided by docs.microsoft.com:

Table 1.30: The description of the arguments
Table 1.29: The description of the arguments

You can execute the function by itself if you have all the requisite parameters. The mode is set to Limited in this example, and this will return NULL values for all description columns:

SELECT OBJECT_NAME(object_id) as TableName,* 
FROM SYS.dm_db_page_info(6, 1, 1368, 'Limited')

The output is as follows:

Figure 1.31: Output with LIMITED mode
Figure 1.30: Output with LIMITED mode

Using the Detailed mode, you will get much more descriptive information than provided in the previous example. In this example, you can see that the NULL values have been replaced with descriptive information.

SELECT OBJECT_NAME(object_id) as TableName,* 
FROM SYS.dm_db_page_info(6, 1, 1368, 'Detailed')

The output is as follows:

Figure 1.32: Output with Detailed mode
Figure 1.31: Output with Detailed mode

To see a full list of all the columns returned, go to https://docs.microsoft.com/en-us/sql/relational-databases/system-dynamic-management-views/sys-dm-db-page-info-transact-sql?view=sqlallproducts-allversions.

sys.fn_pagerescracker

In the previous example, you saw how to pass parameters to this new function manually. Fortunately, the parameters can be directly retrieved from sys.dm_exec_requests or sys.processes. To make this work, we added a new column called page_resource. The page_resource column returns the page ID, the file ID, and the database ID. It is also important to highlight that the new page_resource column in sys.dm_exec_request will be NULL when WAIT_RESOURCE does not have a valid value.

However, the page_resource column stores the data as an 8-byte hexadecimal value that needs to be converted. Therefore, we have added a new function called sys.fn_pagerescracker. This function returns the page ID, the file ID, and the database ID for the given page_resource value.

It is important to note that we require the user to have VIEW SERVER STATE permission on the server to run sys.fn_PageResCracker.

In this example, the page_resource column is being passed into the sys.fn_PageResCracker function, and then the database ID, file ID, and Page ID are passed to sys.dm_db_page_info:

SELECT OBJECT_NAME(page_info.object_id) AS TableName,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

The output is as follows:

Figure 1.33: Page resource column is being passed into a function
Figure 1.32: Page resource column is being passed into a function

You can read more here: https://docs.microsoft.com/en-us/sql/relational-databases/system-functions/sys-fn-pagerescracker-transact-sql?view=sql-server-2017.

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image