How to get the latest LSN of sqlserver database?

363 views
Skip to first unread message

Hongshun Wang

unread,
Dec 12, 2023, 1:40:11 AM12/12/23
to debezium
Current, SqlServerConnection provides getMaxTransactionLsn and getMaxLsn method. However,  as shown in https://stackoverflow.com/questions/77639528/whats-the-difference-between-sys-fn-cdc-get-max-lsn-and-max-value-of-cdc-lsn,  both methods seem no difference. Both get the MAX value of start_lsn from cdc.lsn_time_mapping.

However,  because the capture process extracts change data from the transaction log, there is a built in latency between the time that a change is committed to a source table and the time that the change appears within its associated change table. 

The the MAX value of start_lsn from cdc.lsn_time_mapping is smaller than the latest LSN of whole sqlserver database(also mean max LSN of the transaction log). For example, in https://stackoverflow.com/questions/29477391/cdc-data-only-shows-up-after-5-minutes, this developer find that CDC Data Only Shows up After 5 Minutes.

I wonder how to get the the latest LSN of whole sqlserver database rather than CDC table's LSN? 
Looking forward to hear from you.

Best,
Hongshun Wang

jiri.p...@gmail.com

unread,
Dec 12, 2023, 1:44:39 AM12/12/23
to debezium
Hi,

you can try fn_dblog

J.

Message has been deleted

Hongshun Wang

unread,
Dec 12, 2023, 2:55:01 AM12/12/23
to debezium
Hi jiri
Thanks for your answer.It seems exactly what I want. 

It's no wonder I cannot find the document because it's not documented on official documentation See https://learn.microsoft.com/en-us/answers/questions/269017/using-fn-dblog-cause-we-lost-support)

Is there any other documental method?
On Tuesday, December 12, 2023 at 3:50:50 PM UTC+8 Hongshun Wang wrote:
Is there any other documental method?
Reply all
Reply to author
Forward
0 new messages