Skip to content

Latest commit

 

History

History
72 lines (55 loc) · 3.66 KB

File metadata and controls

72 lines (55 loc) · 3.66 KB
title sys.dm_db_log_space_usage (Transact-SQL)
description The sys.dm_db_log_space_usage dynamic management view returns space usage information for the transaction log.
author rwestMSFT
ms.author randolphwest
ms.date 09/07/2025
ms.service sql
ms.subservice system-objects
ms.topic conceptual
ms.custom
ignite-2025
f1_keywords
sys.dm_db_log_space_usage
sys.dm_db_log_space_usage_TSQL
dm_db_log_space_usage
dm_db_log_space_usage_TSQL
helpviewer_keywords
sys.dm_db_log_space_usage dynamic management view
dev_langs
TSQL
monikerRange =azuresqldb-current || >=sql-server-2016 || >=sql-server-linux-2017 || =azuresqldb-mi-current || =fabric-sqldb

sys.dm_db_log_space_usage (Transact-SQL)

[!INCLUDE SQL Server Azure SQL Database Azure SQL Managed Instance FabricSQLDB]

Returns space usage information for the transaction log.

Note

All transaction log files are combined.

Column name Data type Description
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.
total_log_size_in_bytes bigint The size of the log
used_log_space_in_bytes bigint The occupied size of the log
used_log_space_in_percent real The occupied size of the log as a percent of the total log size
log_space_in_bytes_since_last_backup bigint The amount of space used since the last log backup
Applies to: [!INCLUDE sssql14-md] and later versions, and [!INCLUDE ssSDS].

Permissions

[!INCLUDE sssql19-md] and earlier versions require VIEW SERVER STATE permission.

[!INCLUDE sssql22-md] and later versions, and [!INCLUDE ssazuremi-md] require VIEW SERVER PERFORMANCE 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.

Examples

A. Determine the amount of free log space in tempdb

The following query returns the total free log space in megabytes (MB) available in tempdb.

USE tempdb;
GO

SELECT (total_log_size_in_bytes - used_log_space_in_bytes) * 1.0 / 1024 / 1024 AS [free log space in MB]
FROM sys.dm_db_log_space_usage;

Related content