Skip to content

Latest commit

 

History

History
69 lines (55 loc) · 3.57 KB

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

File metadata and controls

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

sys.dm_db_log_space_usage (Transact-SQL)

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

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: [!INCLUDEsssql14-md] and later, [!INCLUDEssSDS].

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.

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;  

Next steps