Skip to content

Latest commit

 

History

History
106 lines (74 loc) · 7.03 KB

sys-dm-db-session-space-usage-transact-sql.md

File metadata and controls

106 lines (74 loc) · 7.03 KB
title description author ms.author ms.date ms.service ms.subservice ms.topic f1_keywords helpviewer_keywords dev_langs monikerRange
sys.dm_db_session_space_usage (Transact-SQL)
sys.dm_db_session_space_usage (Transact-SQL) returns the number of pages allocated and deallocated by each session for the tempdb system database
rwestMSFT
randolphwest
06/19/2023
sql
system-objects
reference
dm_db_session_space_usage_TSQL
dm_db_session_space_usage
sys.dm_db_session_space_usage
sys.dm_db_session_space_usage_TSQL
sys.dm_db_session_space_usage dynamic management view
TSQL
>=aps-pdw-2016||=azuresqldb-current||=azure-sqldw-latest||>=sql-server-2016||>=sql-server-linux-2017||=azuresqldb-mi-current

sys.dm_db_session_space_usage (Transact-SQL)

[!INCLUDE sql-asdb-asdbmi-asa-pdw]

Returns the number of pages allocated and deallocated by each session for the database.

Note

This view is applicable only to the tempdb database.

Note

To call this from [!INCLUDEssazuresynapse-md] or [!INCLUDEssPDW], use the name sys.dm_pdw_nodes_db_session_space_usage. [!INCLUDEsynapse-analytics-od-unsupported-syntax]

Column name Data type Description
session_id smallint Session ID.

session_id maps to session_id in sys.dm_exec_sessions.
database_id smallint Database ID.

In [!INCLUDE ssazure-sqldb], the values are unique within a single database or an elastic pool, but not within a logical server.
user_objects_alloc_page_count bigint Number of pages reserved or allocated for user objects by this session.
user_objects_dealloc_page_count bigint Number of pages deallocated and no longer reserved for user objects by this session.
internal_objects_alloc_page_count bigint Number of pages reserved or allocated for internal objects by this session.
internal_objects_dealloc_page_count bigint Number of pages deallocated and no longer reserved for internal objects by this session.
user_objects_deferred_dealloc_page_count bigint Number of pages which have been marked for deferred deallocation.

Note: Introduced in service packs for [!INCLUDEssSQL11] and [!INCLUDEssSQL14].
pdw_node_id int Applies to: [!INCLUDEssazuresynapse-md], [!INCLUDEssPDW]

The identifier for the node that this distribution is on.

Permissions

On [!INCLUDEssNoVersion_md] and SQL Managed Instance, requires VIEW SERVER STATE permission.

On SQL Database Basic, S0, and S1 service objectives, and for databases in elastic pools, the server admin account, the Microsoft Entra admin account, or membership in the ##MS_ServerStateReader## server role is required. On all other SQL Database service objectives, either the VIEW DATABASE STATE permission on the database, or membership in the ##MS_ServerStateReader## server role is required.

Permissions for SQL Server 2022 and later

Requires VIEW SERVER PERFORMANCE STATE permission on the server.

Remarks

IAM pages are not included in any of the allocation or deallocation counts reported by this view.

Page counters are initialized to zero (0) at the start of a session. The counters track the total number of pages that have been allocated or deallocated for tasks that are already completed in the session. The counters are updated only when a task ends; they do not reflect running tasks.

A session can have multiple requests active at the same time. A request can start multiple threads, tasks, if it is a parallel query.

For more information about the sessions, requests, and tasks, see sys.dm_exec_sessions (Transact-SQL), sys.dm_exec_requests (Transact-SQL), and sys.dm_os_tasks (Transact-SQL).

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

Physical joins

:::image type="content" source="../../relational-databases/system-dynamic-management-views/media/join-dm-db-session-space-usage-1.svg" alt-text="Diagram of physical joins for sys.dm_db_session_space_usage.":::

Relationship cardinalities

From To Relationship
dm_db_session_space_usage.session_id dm_exec_sessions.session_id One-to-one

Next steps

Dynamic Management Views and Functions (Transact-SQL)
Database Related Dynamic Management Views (Transact-SQL)
sys.dm_exec_sessions (Transact-SQL)
sys.dm_exec_requests (Transact-SQL)
sys.dm_os_tasks (Transact-SQL)
sys.dm_db_task_space_usage (Transact-SQL)
sys.dm_db_file_space_usage (Transact-SQL)