sys.dm_db_log_space_usage (Transact-SQL)sys.dm_db_log_space_usage (Transact-SQL)

適用於: 是SQL Server 否Azure SQL Database 否Azure Synapse Analytics (SQL DW) 否平行處理資料倉儲 APPLIES TO: yesSQL Server yesAzure SQL Database noAzure Synapse Analytics (SQL DW) noParallel Data Warehouse

傳回空間供交易記錄的使用方式資訊。Returns space usage information for the transaction log.

注意

所有交易記錄檔會都結合。All transaction log files are combined.

資料行名稱Column name 資料類型Data type 描述Description
database_iddatabase_id smallintsmallint 資料庫識別碼。Database ID.
total_log_size_in_bytestotal_log_size_in_bytes bigintbigint 記錄檔大小The size of the log
used_log_space_in_bytesused_log_space_in_bytes bigintbigint 記錄檔佔用的大小The occupied size of the log
used_log_space_in_percentused_log_space_in_percent realreal 以記錄檔大小總計的百分比表示的記錄檔佔用的大小The occupied size of the log as a percent of the total log size
log_space_in_bytes_since_last_backuplog_space_in_bytes_since_last_backup bigintbigint 最後一個記錄備份之後所使用的空間量The amount of space used since the last log backup
適用於: SQL Server 2014 (12.x)SQL Server 2014 (12.x)透過SQL Server 2019 (15.x)SQL Server 2019 (15.x)SQL DatabaseSQL DatabaseApplies to: SQL Server 2014 (12.x)SQL Server 2014 (12.x) through SQL Server 2019 (15.x)SQL Server 2019 (15.x), SQL DatabaseSQL Database.

PermissionsPermissions

SQL ServerSQL Server,需要VIEW SERVER STATE權限。On SQL ServerSQL Server, requires VIEW SERVER STATE permission.
SQL DatabaseSQL Database Premium 層需要VIEW DATABASE STATE資料庫的權限。On SQL DatabaseSQL Database Premium Tiers, requires the VIEW DATABASE STATE permission in the database. SQL DatabaseSQL Database標準和基本層,則需要伺服器系統管理員Azure Active Directory 管理員帳戶。On SQL DatabaseSQL Database Standard and Basic Tiers, requires the Server admin or an Azure Active Directory admin account.

範例Examples

A.A. 判斷的可用記錄檔空間量在 tempdb 中Determine the Amount of Free Log Space in tempdb

下列查詢會傳回可用的總記錄空間 (mb) 可在 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

動態管理檢視與函數 (Transact-SQL) Dynamic Management Views and Functions (Transact-SQL)
與資料庫相關動態管理檢視(Transact SQL) Database Related Dynamic Management Views (Transact-SQL)
sys.dm_db_file_space_usage sys.dm_db_file_space_usage
sys.dm_db_task_space_usage (-SQL)) sys.dm_db_task_space_usage (Transact-SQL)
sys.dm_db_session_space_usage (Transact-SQL)sys.dm_db_session_space_usage (Transact-SQL)
sys.dm_db_log_info (Transact-SQL) sys.dm_db_log_info (Transact-SQL)
sys.dm_db_log_stats (Transact-SQL)sys.dm_db_log_stats (Transact-SQL)