Share via


sys.dm_db_file_space_usage

Returns space usage information for each file in the database.

Note

In SQL Server 2005, this view is applicable only to the tempdb database.

Column name Data type Description

database_id

smallint

Database ID.

file_id

smallint

File ID.

file_id maps to file_id in sys.dm_io_virtual_file_stats and to fileid in sys.sysfiles.

unallocated_extent_page_count

bigint

Total number of pages in the unallocated extents in the file. For more information, see Pages and Extents.

Unused pages in allocated extents are not included.

version_store_reserved_page_count

bigint

Total number of pages in the uniform extents allocated for the version store. Version store pages are never allocated from mixed extents.

IAM pages are not included, because they are always allocated from mixed extents. PFS pages are included if they are allocated from a uniform extent.

For more information, see sys.dm_tran_version_store.

user_object_reserved_page_count

bigint

Total number of pages allocated from uniform extents for user objects in the database. Unused pages from an allocated extent are included in the count.

IAM pages are not included, because they are always allocated from mixed extents. PFS pages are included if they are allocated from a uniform extent.

You can use the total_pages column in the sys.allocation_units catalog view to return the reserved page count of each allocation unit in the user object. However, note that the total_pages column includes IAM pages.

internal_object_reserved_page_count

bigint

Total number of pages in uniform extents allocated for internal objects in the file. Unused pages from an allocated extent are included in the count.

IAM pages are not included, because they are always allocated from mixed extents. PFS pages are included if they are allocated from a uniform extent.

There is no catalog view or dynamic management object that returns the page count of each internal object.

mixed_extent_page_count

bigint

Total number of allocated and unallocated pages in allocated mixed extents in the file. Mixed extents contain pages allocated to different objects. This count does include all the IAM pages in the file.

Permissions

Requires VIEW SERVER STATE permission on the server.

Remarks

Page counts are always at the extent level. Therefore, page count values will always be a multiple of eight. The extents that contain Global Allocation Map (GAM) and Shared Global Allocation Map (SGAM) allocation pages are allocated uniform extents. They are not included in the previously described page counts.

The content of the current version store is in sys.dm_tran_version_store. Version store pages are tracked at the file level instead of the session and task level, because they are global resources. A session may generate versions, but the versions cannot be removed when the session ends. Version store cleanup must consider the longest running transaction that needs access to the particular version. The longest running transaction related to version store clean-up can be discovered by viewing the elapsed_time_seconds column in sys.dm_tran_active_snapshot_database_transactions.

Frequent changes in the mixed_extent_page_count column may indicate heavy use of SGAM pages. When this occurs, you may see many PAGELATCH_UP waits in which the wait resource is an SGAM page. For more information, see sys.dm_os_waiting_tasks, sys.dm_os_wait_stats, and sys.dm_os_latch_stats. For more information about SGAM pages, see Managing Extent Allocations and Free Space.

User Objects

The following objects are included in the user object page counters:

  • User-defined tables and indexes
  • System tables and indexes
  • Global temporary tables and indexes
  • Local temporary tables and indexes
  • Table variables
  • Tables returned in the table-valued functions

Internal Objects

Internal objects are only in tempdb. The following objects are included in the internal object page counters:

  • Work tables for cursor or spool operations and temporary large object (LOB) storage
  • Work files for operations such as a hash join
  • Sort runs

Relationship Cardinalities

From To Relationship

sys.dm_db_file_space_usage.database_id, file_id

sys.dm_io_virtual_file_stats.database_id, file_id

One-to-one

Examples

For examples that use the sys.dm_db_file_space_usage view, see Troubleshooting Insufficient Disk Space in tempdb.

See Also

Reference

Dynamic Management Views and Functions
Database Related Dynamic Management Views
sys.dm_db_task_space_usage
sys.dm_db_session_space_usage

Other Resources

Pages and Extents
Troubleshooting Insufficient Disk Space in tempdb

Help and Information

Getting SQL Server 2005 Assistance