Reputation: 5453
What is the meaning of Log Sequence Number? I know that it is of type binary and 10bytes long and it corresponds to the time the transaction happen in DB. But is this a high precision date-time value that is stored in some efficient binary format or is this a function of date-time and something else (for example the serial number of transactions that happen at the same milli second). I did a lot of searching but couldn't find a good answer to this.
Can any one explain with a formula or function that is used to derive the LSN from date-time or anything.
Upvotes: 18
Views: 48968
Reputation: 151
First of all, sorry for replying on dead post. I came to this thread while searching other operations based on LSN. LSN is nothing but sequential number, as it specifies - Log Sequence Number generated in three hexadecimal parts like 00000016:0000003c:0001 and these parts are as below:
Generally any DB operation along with start/end of transaction would be stored and each operation of the transaction, obviously with start and commit operation would get LSN in sequential order. Those are not related to any timestamp but can be mapped with timestamp based on sys function. @max has already replied for that.
Any commit operation towards transaction, force to switch to new log block and middle part would be incremented, otherwise last part would be increased based on the size of VLF.
Upvotes: 9
Reputation: 425803
There is no guaranteed way to derive it, but you can guess it from msdb.dbo.backupset
on the machine you did the backup on:
SELECT last_lsn
FROM msdb.dbo.backupset
WHERE backup_start_date = @backup_date
This is of course not exact and not reliable.
Upvotes: 1
Reputation: 7161
It is an increasing sequence (1,2,3,4,...), not a date time value. From the Microsoft documentation:
The log sequence number (LSN) value is a three-part, uniquely incrementing value. It is used for maintaining the sequence of the transaction log records in the database. This allows SQL Server to maintain the ACID properties and to perform appropriate recovery actions.
Upvotes: 6
Reputation: 300769
Every record in the SQL Server transaction log is uniquely identified by a log sequence number (LSN). LSNs are ordered such that if LSN2 is greater than LSN1, the change described by the log record referred to by LSN2 occurred after the change described by the log record LSN.
From here.
You should not be concerned with how these are generated.
Upvotes: 22