Jam*_*ins 3 sql-server-2008 functions
如果我DBCC LOGINFO对我的数据库运行未记录 的字段,则返回的字段之一是 CreateLSN。这是创建 VLF 时格式为 1629000000070500011 的 LSN。现在已经很长时间了,磁盘使用情况报告的自动增长值早已不复存在。我想将 LSN 转换为日期/时间
对于一次性解决方案,我试过这个
select sys.fn_cdc_map_lsn_to_time ( convert(binary,1629000000070500011) )
Run Code Online (Sandbox Code Playgroud)
但我得到了错误
无效的对象名称 'cdc.lsn_time_mapping'
我觉得我错过了一些简单的东西,但它在暗指我。
每次对数据库进行修改时,LSN 都会增加,而不管修改是何时进行的。
sys.fn_cdc_map_lsn_to_time依赖于启用了变更数据捕获的当前数据库,它会自动在 cdc 模式中创建多个对象。的定义fn_cdc_map_lsn_to_time表明:
create function [sys].[fn_cdc_map_lsn_to_time]
(
@lsn binary(10)
)
returns datetime
with returns null on null input
as
begin
declare @lsn_end_time datetime
select @lsn_end_time = tran_end_time
from [cdc].[lsn_time_mapping]
where start_lsn = @lsn
return @lsn_end_time
end
Run Code Online (Sandbox Code Playgroud)
因此,除非当前数据库具有cdc.lsn_time_mapping对象(我不确定这是视图还是表),否则该函数将无法工作。
您链接的文档页面中的注释说:
此函数可用于根据更改数据行中返回的 __$start_lsn 值确定提交更改的时间。
我推断该函数实际上返回预先记录的 LSN 到时间戳元组,而不是实际将 LSN 转换为时间戳。
@RemusRusanu在他的博客上有一篇关于 LSN 的精彩文章