SQL Server Log Explorer
Restore Data

What is LSN in SQL Server and How does the Backup Chain Use It?

Andrew Jackson Modified: 6 Minutes Reading
On this page

Quick Answer

LSN in SQL Server stands for log sequence number. Every log record gets one LSN. Every new record gets a higher LSN than the one before. Log backups store a first LSN and a last LSN. Your next log backup starts where the previous one ended. Any gap in that chain stops a restore with error 4305. Compare the values in msdb before you restore.

You meet LSN values in backup history, in restore errors and in fn_dblog output. All three places show the number in a different format so matching them by eye is hard.

This guide shows one LSN in all three formats from a test on SQL Server 2022. You will also see the exact text of error 4305 and how to find the broken link in your backup chain.

What do LSN Values Look Like in Real Output?

Microsoft states that every log record is identified by a log sequence number. Every new record gets a higher LSN than the record before it, which makes the LSN an ordering key for modifications.

We executed one full backup and two log backups on SQL Server 2022 (RTM CU26) Express on Linux. Backup history in msdb stored the LSNs as long numbers.

Backup type first_lsn last_lsn
Full 42000000023200001 42000000023500001
Log 1 42000000023200001 42000000025700001
Log 2 42000000025700001 42000000028100001

Log functions show the same idea in hex. Our sys.dm_db_log_stats output from the same test is below.

log_min_lsn      0000002A:00000103:0002
log_end_lsn      0000002A:00000122:0001
log_backup_lsn   0000002A:00000119:0001

Hex 0x119 equals 281. That matches the end of log backup 2 in the table, which is 42000000028100001.

How do You Convert a Hex LSN to the Number in Backup History?

Microsoft documents the hex format as VLF ID, log block ID and log record ID. Its sample value is below where 0x31 is the VLF ID.

00000031:00000da0:0001

Backup history joins the same three parts in decimal. VLF ID drops leading zeros while log block ID pads to 10 digits and log record ID pads to 5 digits.

Part Hex value Decimal Padded to
VLF ID 0000002A 42 No padding
Log block ID 00000121 289 0000000289
Log record ID 0001 1 00001

Joined together, the top row of our fn_dblog output became 42000000028900001. That row is a LOP_COMMIT_XACT record right before the log end at 0x122.

DECLARE @l varchar(24) = '0000002A:00000121:0001';
SELECT CAST(CONVERT(INT, CONVERT(VARBINARY(4), '0x' + LEFT(@l, 8), 1)) AS varchar(10))
 + RIGHT('0000000000' + CAST(CONVERT(INT, CONVERT(VARBINARY(4), '0x' + SUBSTRING(@l, 10, 8), 1)) AS varchar(10)), 10)
 + RIGHT('00000' + CAST(CONVERT(INT, CONVERT(VARBINARY(2), '0x' + SUBSTRING(@l, 19, 4), 1)) AS varchar(10)), 5) AS numeric_lsn;

Our guide on using fn_dblog to find a transaction in a backup shows where these hex values come from.

How does LSN in SQL Server Link Your Backup Chain?

Every log backup fits only when its first LSN matches the end of the backup before it. Log 2 in our test started at 42000000025700001, which is where log 1 ended.

Log 1 started at 42000000023200001. That is earlier than the full backup end at 42000000023500001 and the overlap is normal because the first log backup attaches to the full backup.

Heads Up

Log backups store their full backup in database_backup_lsn. Both log backups in our test pointed to 42000000023200001, the first LSN of the full backup.

What does a Gap in the LSN Chain Look Like?

We dropped the test database and restored the full backup with NORECOVERY. Then we skipped log 1 and applied log 2. SQL Server returned this message.

Msg 4305, Level 16, State 1, Line 4
The log in this backup set begins at LSN 42000000025700001, which is too recent to apply to the database. An earlier log backup that includes LSN 42000000023500001 can be restored.
Msg 3013, Level 16, State 1, Line 4
RESTORE LOG is terminating abnormally.

Two LSNs appear in the message. Your log backup begins at the first number and the database still needs the second number. Find the log backup that includes that second number.

Applying log 1 and log 2 in order with NORECOVERY and then RECOVERY brought the database online and returned all 3 test rows.

Situation What the LSN shows What to do
Error 4305 on a log restore The log backup begins after the LSN the database needs Restore the earlier log backup named in the message first
first_lsn of a backup is higher than the previous last_lsn A log backup is missing from the chain Find the missing file or restore up to the end of the last good backup
Log backup fails after a database restore The chain restarted from a new full backup Take a full backup and then start log backups again
log_backup_lsn is far behind log_end_lsn Much log has no backup yet Take a log backup and check log_reuse_wait_desc

Which Versions and Permissions Apply?

System Specifications

Component Requirement
Operating system Any system that hosts your SQL Server version. We tested on Linux.
Access to msdb Permission to query msdb.dbo.backupset
Access to log records sysadmin rights for fn_dblog

Software Specifications

Item Requirement
sys.dm_db_log_stats SQL Server 2016 SP2 and later according to Microsoft
Permission for sys.dm_db_log_stats VIEW SERVER STATE up to SQL Server 2019 and VIEW SERVER PERFORMANCE STATE from SQL Server 2022
Test version SQL Server 2022 RTM CU26 Express

FAQs

What does LSN Stand for in SQL Server?

LSN stands for log sequence number. SQL Server gives one to every record in the transaction log and a higher number always marks a later record.

Is the LSN in Backup History the Same as the LSN in the Log?

Yes. Backup history shows the long decimal form and fn_dblog shows the hex form with three parts. Our conversion above turns one into the other.

Can Two Log Records have the Same LSN?

No. Microsoft states every new log record gets an LSN higher than the record before it. That makes the values unique inside one database log.

Why does SQL Server Say the Log Begins at an LSN That is Too Recent?

That is error 4305 and it means the log backup you applied begins after the point where the database stopped. Apply the earlier log backup first or follow our guide on error 4305.

How do You Find a Broken Log Backup Chain?

List the backups in backup history by time and compare every first LSN with the previous last LSN. Our guide on a broken log backup chain shows the full check.

Does a Tail Log Backup Use an LSN Too?

Yes. Tail log backups continue from the last log backup so they need the same LSN fit. Our guide on the tail log backup explains when you need one.

About this guide

We checked this guide against Microsoft documentation on 5 Dec 2026. We executed the backups, the restore with the missing log backup and the log statistics query on SQL Server 2022 (RTM CU26) Express on Linux.

Microsoft documents the LSN format on its transaction log architecture page and the log columns on its sys.dm_db_log_stats page.