sys.databases 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 即時real 記錄檔大小總計百分比的已佔用大小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.

權限Permissions

SQL ServerSQL Server上, VIEW SERVER STATE需要許可權。On SQL ServerSQL Server, requires VIEW SERVER STATE permission.
SQL DatabaseSQL Database高階層級上, 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

下列查詢會傳回 tempdb 中可用的總可用記錄空間(以 mb 為單位)。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
dm_db_task_space_usage (Transact-sql) sys.dm_db_task_space_usage (Transact-SQL)
dm_db_session_space_usage (Transact-sql)sys.dm_db_session_space_usage (Transact-SQL)
dm_db_log_info (Transact-sql) sys.dm_db_log_info (Transact-SQL)
dm_db_log_stats (Transact-sql)sys.dm_db_log_stats (Transact-SQL)