Microsoft released preview of SQL Server 2019 recently in Ignite 2018. With every release of SQL Server is enriched with new dynamic management view and functions along with enhancements to existing features.
In this article, we will view the newly introduced dynamic management function (DMF) sys.dm_db_page_info and explore the different scenarios around it.
Overview of sys.dm_db_page_infoSQL Server 2019 provides new database management function ‘sys. dm_db_page_info’ to get information about the pages in SQL Server. Prior to SQL Server 2019, we use undocumented dynamic management function sys.dm_db_database_page_allocations and DBCC Page to get details information about the page in SQL Server for the tables, indexes.
Dynamic Management function sys.dm_db_page_info DMF is introduced to replace DBCC Page function but this DMF returns only page header information while DBCC page shows complete details of the page. We will see this later in the demo section.
Before we move further, let us take a look of new dynamic management function (DMF) syntax and parameters.
Syntax for sys.dm_db_page_infosys.dm_db_page_info ( DatabaseId, FileId, PageId, Mode )
Below are the parameters to pass into sys.dm_db_page_info.
Argument Description Null allowed Allowed ValuesDatabaseId
It is unique ID of the database
No
DBID, or we can use DB_ID() for the current database
FileId
It is ID of the database file
No
DB file id
PageId
It is ID of the page we want to examine
No
PageID
Mode
It shows the level of detail in the output of the function
No
LIMITED No information about description columns
DETAILED it gives information about detailed columns as well
We require the VIEW DATABASE STATE permission in the database. We can provide permissions to run with below command.
GRANT VIEW DATABASE STATE TO [login]To move further, let us create the sample database and data.
Create Database SQL2019 Go Use SQL2019 Go Create table DemoSQL2019 ( ID int identity(1,1), Name varchar(10) ) Go Insert into DemoSQL2019 Values ('SqlShack')
In this article, we will take an overview of new DMF sys.dm_db_page_info along and compare it with the previously used DMF sys.dm_db_database_page_allocations.
Now let us view the information about all the pages and extents allocated for the table using the DMF sys.dm_db_database_page_allocations. This is undocumented DMF introduced in SQL Server 2012.
Syntax for sys.dm_db_database_page_allocations:
sys.dm_db_database_page_allocations
(@DatabaseId , @TableId , @IndexId , @PartionID , @Mode)
Argument Description Null allowed Allowed ValuesDatabaseId
It is unique ID of the database.
No
DB ID
TableID
It is ID of the database file.
Yes
Table ID or Null
IndexID
It is ID of the page we want to examine
Yes
Index ID or Null
PartionID
We can pass PatitionID if we require.
Yes
partitionID or Null
Mode
It shows the level of detail in the output of the function
No
LIMITED If we use this parameter, it does not show any information about description columns.
DETAILED it gives information about detailed columns as well.
We cannot provide Null value in this parameter.
Now run the below query to get information about allocated page id and page type description.
Select database_id,DB_name(database_id) as [Database], allocated_page_page_id , page_type_desc from sys.dm_db_database_page_allocations(DB_ID(),null,null,null,'Detailed')In the above query, we can directly pass the DB ID as well. We can get the DB ID from the sp_helpdb or sys.sysdatabases.

Now we can view the information about any particular page from DBCC Page.
Below is the syntax for DBCC Page:
dbcc page ( {‘dbname’ | dbid}, filenum, pagenum [, printopt={0|1|2|3} ])Printout values can be as:
0 Prints only page header related information 1 Prints page header and page slot array dump with hex dump for each row 2 Prints page header and whole page hex dump 3 Prints detailed information of per row along with page headerNote: We need to turn on trace flag 3604 for DBCC Page to show output in SQL Server Management Studio.
DBCC TRACEON(3604) DBCC page (6,1,157,3) WITH TABLERESULTS
We can see that DBCC Page gives detailed information about the page.
Now if we view the same thing from the newly introduced sys.dm_db_page_info. We will use the same page id as used before for a comparison purpose.
We can see here that sys.dm_db_page_info gives one row with all the page information for a given parameter in the detailed mode as specified by us.
Note here, we are using the mode as limited so we can see there are some columns showing null values (highlighted by blue arrow)
Select * from sys.dm_db_page_info(6,1,157,’limited’)
Important columns in Sys.dm_db_page_info are:
Column Descriptiondatabase_id
Database ID
page_type_desc
Page type description such as data page, index page, IAM page
page_level
It shows the Level of the page in the index. For a leaf level, its value is 0
slot_count
It shows the total slot counts. It is number of rows for a data page,
ghost_rec_count
A number of ghost records that are marked for deletion.
is_iam_pg
If that particular page is IAM page, its value