Why This Error Happens
Error 4334 occurs when a RESTORE LOG or RESTORE DATABASE command uses the STOPATMARK or STOPBEFOREMARK clause with a mark name that cannot be located in the msdb.dbo.logmarkhistory table or within the transaction log being restored. This typically happens because the named transaction was never committed with WITH MARK, the marked transaction occurred on a different database than the one being restored, or the backup chain being restored does not actually contain the LSN range where that mark was recorded. Database corruption in the msdb system database or a mismatch between the source and target server’s log mark history can also trigger this error.
Step-by-Step Resolution Guide
Step 1: Verify the Mark Name Exists and Is Correct
- Run
SELECT * FROM msdb.dbo.logmarkhistory WHERE name = 'YourMarkName'on the source instance to confirm the mark was actually recorded. - Check for typos, case sensitivity, or extra whitespace in the mark name used in your
RESTOREstatement. - Confirm the transaction was committed using
BEGIN TRANSACTION YourMarkName WITH MARK 'description'followed by aCOMMIT.
Step 2: Confirm the Mark Belongs to the Correct Database and Log Chain
- Check the
database_namecolumn inmsdb.dbo.logmarkhistoryto ensure the mark was logged against the same database you are restoring. - Verify that the backup files being restored (full, differential, and log backups) span the LSN range containing the mark, using
RESTORE HEADERONLYandRESTORE LOG ... WITH NORECOVERYin sequence. - Ensure no log backups are missing from the restore sequence — a gap in the log chain will cause the LSN to never appear.
Step 3: Restore Using LSN or Time-Based Alternative Instead of Mark Name
- If the mark cannot be validated, switch to
STOPAT = 'yyyy-mm-dd hh:mm:ss'to restore to a known point in time instead. - Alternatively, use
STOPBEFOREMARK = 'YourMarkName' AFTER 'datetime'to help SQL Server disambiguate marks with duplicate names across multiple transactions. - Example command:
RESTORE LOG YourDB FROM DISK = 'E:\Backups\YourDB_log.trn' WITH STOPAT = '2025-01-15T14:30:00', RECOVERY.
Step 4: Rebuild or Repair the msdb Marked Transaction Table (If Corrupted)
- Run
DBCC CHECKDB('msdb')to rule out corruption in the system database on both source and target instances. - If corruption is found, restore
msdbfrom a known-good backup or runDBCC CHECKDB('msdb', REPAIR_ALLOW_DATA_LOSS')in single-user mode as a last resort. - Restart the SQL Server service via
services.mscornet stop MSSQLSERVER && net start MSSQLSERVERafter repairs on Windows Server 2025/Windows 11.
Alternative or Verification Steps
- After restoring, run
RESTORE HEADERONLY FROM DISK = 'YourBackupFile'and confirm theLastLSNandFirstLSNvalues bracket the LSN logged inlogmarkhistoryfor your mark name. - If the marked transaction restore still fails, bypass marks entirely and restore to the latest available point using
WITH RECOVERYwithout anySTOPAT/STOPATMARKclause, then manually verify data integrity withDBCC CHECKDBon the restored database.