显示有关检查点文件的信息,包括文件大小、物理位置和事务 ID。
备注
对于未关闭的当前检查点,sys.dm_db_xtp_checkpoint_files 的状态列对于新文件将为 UNDER CONSTRUCTION。如果事务日志自上个检查点后增长到 512 MB,或者如果发出 CHECKPOINT 命令 (CHECKPOINT (Transact-SQL)),检查点将自动关闭。
内存优化的文件组在内部使用文件流文件存储内存中表中插入和删除的行。 有两种类型的文件。 一个数据文件,其中包含插入的行,一个差异文件,其中包含删除的行。 为每个数据文件预先分配 128 MB 大小,但是,如果有长期运行的事务,或在手动合并迫使所得的目标文件大于 128 MB 时,此文件可变大。
有关详细信息,请参阅创建和管理用于内存优化的对象的存储。
适用于:SQL Server(SQL Server 2014 到当前版本)。 |
列名 |
类型 |
说明 |
---|---|---|
container_id |
int |
数据或差异文件所属的容器 ID(在 sys.database_files 中表示为类型为 FILESTREAM 的文件)。 在 sys.database_files (Transact-SQL) 中与 file_id 联接。 |
container_guid |
uniqueidentifier |
数据或差异文件所属的容器的 GUID。 |
checkpoint_file_id |
GUID |
数据或差异文件的 ID。 |
relative_file_path |
nvarchar(256) |
数据或差异文件的路径(相对于容器的位置)。 |
file_type |
tinyint |
0 表示数据文件。 1 表示差异文件。 如果状态列设置为 6,则为 NULL。 |
file_type_desc |
nvarchar(60) |
文件的类型:如果状态列设置为 6,则为 DATA_FILE、DELTA_FILE 或 NULL。 |
internal_storage_slot |
int |
内部存储数组中的文件的索引。 如果状态列设置为 2 或 3,则为 NULL。 如果检查点文件对状态为 1 (UNDER CONSTRUCTION),则为 NULL。 |
checkpoint_pair_file_id |
uniqueidentifier |
对应的数据或差异文件。 |
file_size_in_bytes |
bigint |
所用文件的大小。 如果状态列设置为 4、5 或 6,则为 NULL。 |
file_size_used_in_bytes |
bigint |
所用文件的已用大小。 如果状态列设置为 4、5 或 6,则为 NULL。 对于仍在填充的检查点文件对,此列将在下一个检查点的后面更新。 |
inserted_row_count |
bigint |
数据文件中的行数。 |
deleted_row_count |
bigint |
差异文件中删除的行数。 |
drop_table_deleted_row_count |
bigint |
删除表影响的数据文件中的行数。 当状态列等于 1 时,应用于数据文件。 显示从已删除表中删除的行计数。 在对已删除表中的行完成内存垃圾回收并且实施了检查点之后,汇总 drop_table_deleted_row_count 统计信息。 如果您在此列中反映删除表统计信息之前重新启动 SQL Server,则统计信息会在恢复过程中更新。 恢复过程不会从已删除表中加载行。 已删除表的统计信息会在加载阶段中进行汇总并在此列中进行报告(恢复完成时)。 |
state |
int |
0 – PRECREATED 1 - UNDER CONSTRUCTION 2 - ACTIVE 3 – MERGE TARGET 4 – MERGED SOURCE 5 – REQUIRED FOR BACKUP/HA 6 – IN TRANSITION TO TOMBSTONE 7 – TOMBSTONE |
state_desc |
nvarchar(60) |
|
lower_bound_tsn |
bigint |
文件中包含事务的下限。 如果状态列不是 1,则为 Null。 |
upper_bound_tsn |
bigint |
文件中包含事务的上限。 如果状态列不是 1,则为 Null。 |
last_backup_page_count |
int |
上次备份时确定的逻辑页计数。 状态列设置为 0、1 或 2 时应用。 如果页计数未知,则为 NULL。 |
delta_watermark_tsn |
int |
写入此差异文件的上个检查点的事务。 这是差异文件的水印。 |
last_checkpoint_recovery_lsn |
nvarchar(23) |
仍需要文件的上个检查点的恢复日志序列号。 |
tombstone_operation_lsn |
nvarchar(23) |
tombstone_operation_lsn 落后于日志截断日志序列号之后,文件将删除。 |
logical_deletion_log_block_id |
bigint |
除非状态列是 6,则为 NULL。 |
权限
要求对服务器具有 VIEW DATABASE STATE 权限。
用例
可按如下方式估算内存中表使用的存储容量:
-- total storage used by in-memory tables
select sum (file_size_in_bytes)/(1024*1024) as file_size_in_MB
from sys.dm_db_xtp_checkpoint_files
where internal_storage_slot is not NULL
可通过以下查询估算每个文件中的可用空间。
注意 percent_full 列。 内存中 OLTP 使用启发式方法找出数据文件的最后一个事务。 根据事务更改的行数,percent full 可能有所不同。 如果完成的检查点导致此文件关闭,则还会影响数据文件的已填充空间。 可能还会看到一个数据文件没有任何行。 删除行之后添加任何行之前进行手动检查点操作可能会产生这种情况。
select *,
str((convert
(float, (file_size_used_in_bytes * (1 - convert (float, deleted_rows)/inserted_rows)))/file_size_in_bytes),
25, 2) as percent_full
from
(
select t.internal_storage_slot, file_size_in_bytes, file_size_used_in_bytes,
(case when inserted_row_count= 0 then 1
when inserted_row_count > 0 then inserted_row_count end) as inserted_rows,
(select deleted_row_count
from sys.dm_db_xtp_checkpoint_files
where internal_storage_slot = t.internal_storage_slot and file_type=1) as deleted_rows
from sys.dm_db_xtp_checkpoint_files as t
where internal_storage_slot is not NULL and file_type=0) as t_t
order by internal_storage_slot
SQL Server 允许最多有 8,192 个数据和差异文件对。 若要查看活动的数据和差异文件对的数量,请使用以下查询。
-- total number of data and delta file pairs
select count (*)
from sys.dm_db_xtp_checkpoint_files
where internal_storage_slot is not NULL and file_type = 0
若要估算用量占总存储容量的百分比,请执行以下操作:
declare @deleted_row_count int;
declare @inserted_row_count int;
declare @effective_row_percentage float
-- get the total deleted row counts by looking at active delta files
select @deleted_row_count = SUM (deleted_row_count)
from sys.dm_db_xtp_checkpoint_files
where state = 2 and file_type = 1
-- get total inserted row count by looking at active data files
select @inserted_row_count = SUM (inserted_row_count)
from sys.dm_db_xtp_checkpoint_files
where state = 2 and file_type = 0
-- get the effective % of active rows after accounting for the deleted rows
-- This number represents the potential space that can be freed up if deleted are removed from storage
select @effective_row_percentage = (1 - convert (float, @deleted_row_count)/@inserted_row_count)
-- Compute the effective usage fill factor for the storage.
-- Effective fill factor computes the effective free space in data files
-- on average after accounting for the deleted rows
-- This should be >= 50% otherwise it is an indication that auto-merge is not keeping up
select
str (convert (varchar(100), ((SUM (file_size_used_in_bytes)*@effective_row_percentage)/SUM (file_size_in_bytes)) *100 ),5, 2)
as [storage usage fill factor]
from sys.dm_db_xtp_checkpoint_files
where state = 2 and file_type = 0