In SQL Server versions before SQL Server 2012, you have to use the undocumented DBCC IND command if you want to know which pages belong to a particular table. Since version 2012, SQL Server provides a simpler (but still undocumented) method to get that information.
The sys.dm_db_database_page_allocations DMF takes five parameters:
The @DatabaseId, @TableId, @IndexId and @PartitionId detail the object whose pages you are interested in. @TableId, @IndexId and @PartitionId can be NULL, the @DatabaseId has to be specified. If for example, you specify the @TableId and @IndexId of a particular index but you pass in NULL for the @PartitionId, the function will return all pages in all partitions for that particular index. If only the @DatabaseId is valued, all (table related) pages in that database are returned.
The @Mode can be either 'LIMITED' or 'DETAILED'. 'LIMITED' returns less information. However, 'DETAILED' uses significantly more resources. Therefore, it should be used only on small sets of pages.
This DMF returns quite a few columns. The full list you can see in the following SELECT statement:
The function returns one row per page that belongs to one of the partitions selected by the parameters.
The columns database_id to partition_id specify the partition to which the page belongs. The three allocation unit columns reference the allocation unit of the page. The preceding rowset_id column is what the sys.allocation_units catalog view calls container_id. The two extent columns identify the first page of the page's extent and the IAM columns tell us which IAM page has the current page cataloged. allocated_page_file_id and allocated_page_page_id contain the information we are really after here. They specify the file id and page number of the current page.
All the other columns give us more detailed information about the page itself, for example the page type or the level of the page within the index. Many of these additional columns are only valued when the @Mode parameter is set to 'DETAILED'.
The screenshot below shows a few of the column returned for one of my example tables:
Since SQL Server 2012, the sys.dm_db_database_page_allocations DMF provides an easier to use alternative to the DBCC IND command. It also provides a lot more information about each page than that DBCC command. However, like DBCC IND, the sys.dm_db_satabase_page_allocations DMF is sadly not part of the official documentation, and as such its functionality cannot be guaranteed.
You must be logged in to post a comment.
Pingback: Hey, where is my BLOB? - sqlity.net