SQL Server – What Are the Three Parts of a LSN?

logssql servertransaction-log

I am curious about what the 3 parts of a Log Sequence Number (LSN) are and how they are generated.

A log sequence number is an ever-increasing, three-part number that uniquely defines the position of a log record within the transaction log. Source

I looked around a bit, and found at least one answer that said I should "not be concerned with how these are generated" but I still want to know.

If I run DBCC FILEHEADER ([AdventureWorks2014], 1) I get results that show me some important LSN's in my AdventureWorks

MaxLSN

45000000001600001

FirstLSN

44000000084000074

RedoStartLSN

45000000001600001

They do seem to have 3 distinct parts, what are they, what do they mean, and how are they generated?

Best Answer

According to Paul Randal in his Pluralsight course "SQL Server: Logging, Recovery, and the Transaction Log" the LSN is composed of three parts:

  • 1) VLF sequence number (4 bytes)
  • 2) Log block number (4 bytes)
  • 3) Log record number (2 bytes)