Fix SQL Server Error 4305 (Log Is Too Recent to Apply)
SQL Server error 4305 says a log backup begins after the point where your database stopped restoring. Msg 4305 comes with Msg 3013 so the log restore ends before it applies the file.
The message names the LSN that the missing log backup must include. This guide reads the LSNs, finds the missing link in the chain and gives four fixes.
Quick SummarySQL Server error 4305 means a log backup begins at an LSN that is too recent for the database. A log backup in the chain is missing or you restored the files out of order. The message gives the LSN that an earlier log backup must include. Query msdb.dbo.backupset to find the file that holds that LSN. Restore the files in chronological order with NORECOVERY. Recover to the last good log backup when one file is lost.
What Does Error 4305 Say About the LSN?
Error 4305 compares two LSNs. The first LSN is where the log file you tried to restore begins. The second LSN is the point where your database stopped.
Msg 4305, Level 16, State 1, Line 1
The log in this backup set begins at LSN 41000000087200001, which is too recent to apply to the database. An earlier log backup that includes LSN 41000000062400001 can be restored.
Msg 3013, Level 16, State 1, Line 1
RESTORE LOG is terminating abnormally.
The LSN values in the example are sample values. Your message shows your own numbers. Practitioners report a mirror message as error 4326, which says the log terminates at an LSN that is too early to apply.
According to Microsoft documentation for applying log backups, you restore the previous full or differential backup first. You then restore every log backup created after it in chronological order. One missing file in that order causes error 4305.
Do You Know?A database in the Restoring state after a NORECOVERY restore is normal. The database waits for the next log backup. Fix SQL database stuck in restoring state explains when the wait is a problem.
Which Case Matches Your Log Restore?
Find your message in the first column and start with the method in the last column.
| What you see | What it means | Start with |
|---|---|---|
| Error 4305 names an earlier log backup | A log backup between the database and this file is missing or out of order | Method 1 |
| Error 4326 says the log is too early | The file ends before the point the database reached | Method 2 |
| No file in msdb holds the LSN | The log backup was lost or never taken | Method 3 |
| A newer full backup exists after the gap | A fresh chain can replace the broken one | Method 4 |
| The error appears on a log shipping secondary | The secondary missed a log file | Method 1 then Method 4 |
How to Fix SQL Server Error 4305?
Every example uses the database OrdersDB. Replace the names and the paths with your own values.
Method 1: Find the Log Backup That Holds the LSN
Use this method first because the message names the LSN you need. Microsoft describes first_lsn as the oldest log record in the backup set and last_lsn as the next log record after the set. A log backup fits your database when its first_lsn is at or below the LSN in the message and its last_lsn is above it.
SELECT bs.backup_set_id, bs.type, bs.first_lsn, bs.last_lsn,
bs.backup_start_date, bs.is_copy_only, bmf.physical_device_name
FROM msdb.dbo.backupset AS bs
INNER JOIN msdb.dbo.backupmediafamily AS bmf
ON bs.media_set_id = bmf.media_set_id
WHERE bs.database_name = N'OrdersDB'
AND bs.type IN ('D', 'I', 'L')
ORDER BY bs.backup_start_date;
The type column shows D for a full backup, I for a differential backup and L for a log backup. Compare the LSN from the message with the first_lsn and last_lsn columns. The row that holds the LSN is the file you restore next.
Read the file header when msdb has no history for the files. RESTORE HEADERONLY returns FirstLSN and LastLSN for every backup set in the file.
RESTORE HEADERONLY FROM DISK = N'D:\Backup\OrdersDB_log2.trn';
The command needs the CREATE DATABASE permission and it does not restore anything.
Method 2: Restore the Backups in Chronological Order
Use this method after Method 1 shows every file. Restore the full backup first and then the log backups in the order of their LSNs.
RESTORE DATABASE OrdersDB
FROM DISK = N'D:\Backup\OrdersDB_full.bak'
WITH NORECOVERY;
RESTORE LOG OrdersDB
FROM DISK = N'D:\Backup\OrdersDB_log1.trn'
WITH NORECOVERY;
RESTORE LOG OrdersDB
FROM DISK = N'D:\Backup\OrdersDB_log2.trn'
WITH NORECOVERY;
RESTORE DATABASE OrdersDB WITH RECOVERY;
Microsoft recommends that you restore every log backup with NORECOVERY and recover the database in a separate step after the last file. The database cannot go further after recovery. Restore database with NORECOVERY explains the options in detail.
Method 3: Recover to the Last Good Log Backup
Use this method when a log backup is lost or damaged. Microsoft states that you can restore only the log backups before the missing file.
RESTORE DATABASE OrdersDB WITH RECOVERY;
Execute the command after the last log backup that SQL Server accepted. The database comes online and the changes in the missing file and after it are gone. Take a new full backup right away so a fresh chain starts.
Heads UpMicrosoft states that no more log backups apply after you recover the database. Recover only when you accept the loss of the later changes. Find the missing file first with Method 1.
Method 4: Start a New Chain From a Newer Full Backup
Use this method when a full or differential backup exists after the gap. Microsoft states that the previous full or differential backup restores first and the log backups after it follow in chronological order.
SELECT bs.type, bs.backup_finish_date, bs.first_lsn, bs.last_lsn,
bs.database_backup_lsn, bmf.physical_device_name
FROM msdb.dbo.backupset AS bs
INNER JOIN msdb.dbo.backupmediafamily AS bmf
ON bs.media_set_id = bmf.media_set_id
WHERE bs.database_name = N'OrdersDB'
AND bs.type IN ('D', 'I')
ORDER BY bs.backup_finish_date DESC;
Restore the newest full backup with NORECOVERY and add the differential backup when one exists. Apply the log backups taken after it with the steps from Method 2. A log shipping secondary follows the same path. Restore a fresh full backup on the secondary and restart the restore job. Troubleshooting log shipping issues in SQL Server lists the other causes of a stopped secondary.
Log Restore Questions Answered
What Is the Difference Between Error 4305 and Error 4326?
Error 4305 says the log begins at an LSN that is too recent. Error 4326 says the log terminates at an LSN that is too early. Both point to a chain that is out of order.
Does Error 4305 Mean a Log Backup Is Damaged?
No. SQL Server read the file and found it at the wrong position in the chain. A damaged file shows another message like error 3203.
Can You Skip a Missing Log Backup?
No. Microsoft states that you can restore only the log backups before the missing file. Later files cannot apply without it.
Does a Copy Only Full Backup Break the Log Chain?
No. Microsoft states that a copy only backup does not affect the overall backup and restore procedures. The IsCopyOnly column in the backup header shows the flag.
Why Does the Database Show Restoring After the Error?
The earlier steps used NORECOVERY. The database waits for the next log backup. Restore the correct file or recover the database with Method 3.
How to Avoid Error 4305 in Restores and Log Shipping?
Name every log backup file with the date and the time. A sorted file list then matches the order of the chain.
Copy the full file set to the restore server before you start. SQL Server log sequence numbers for backups explains how the LSNs connect the files. Fix SQL Server error 3159 shows how to take the tail log backup before a restore.
Who, How and WhyAndrew Jackson, Technical Content Specialist, wrote this guide. The restore order, the recovery rules and the lost file rule follow the Microsoft Learn page on applying log backups. The column meanings follow the Microsoft Learn pages for the backupset table and RESTORE HEADERONLY. The T-SQL was checked for syntax against Microsoft documentation and was not executed on a live server. The text of error 4305 and the mirror message of error 4326 and the log shipping advice come from public practitioner reports because Microsoft has no page for them. The rule that a log backup fits when its first_lsn is at or below the LSN and its last_lsn is above it follows from the Microsoft column descriptions. The guide exists because error 4305 names an LSN and most reports skip how to find the file that holds it.
Key Takeaways
- SQL Server error 4305 means a log backup begins after the point where the database stopped.
- The message names the LSN that an earlier log backup must include.
- msdb.dbo.backupset and RESTORE HEADERONLY show the first and last LSN of every file.
- Restore the files in chronological order with NORECOVERY and recover once at the end.
- Microsoft states that a lost log backup limits the restore to the files before it.
- A newer full backup starts a fresh chain when the gap cannot close.