sys.dm_db_log_space_usage (Transact-SQL)

APPLIES TO: yesSQL Server yesAzure SQL Database noAzure SQL Data Warehouse noParallel Data Warehouse

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.
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: SQL Server 2014 (12.x) through SQL Server 2017, SQL Database.

Permissions

On SQL Server, requires VIEW SERVER STATE permission.
On SQL Database Premium Tiers, requires the VIEW DATABASE STATE permission in the database. On SQL Database Standard and Basic Tiers, requires the Server admin or an Azure Active Directory admin account.

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;  

See Also

Dynamic Management Views and Functions (Transact-SQL)
Database Related Dynamic Management Views (Transact-SQL)
sys.dm_db_file_space_usage
sys.dm_db_task_space_usage (Transact-SQL)
sys.dm_db_session_space_usage (Transact-SQL)
sys.dm_db_log_info (Transact-SQL)
sys.dm_db_log_stats (Transact-SQL)