title | description | author | ms.author | ms.date | ms.service | ms.subservice | ms.topic | helpviewer_keywords | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Recover to a Log Sequence Number (SQL Server) |
In SQL Server, you can use the log sequence number (LSN) to recover to a certain point. This feature is intended for tools vendors. |
MashaMSFT |
mathoma |
10/23/2019 |
sql |
backup-restore |
conceptual |
|
[!INCLUDE SQL Server] This topic is relevant only for databases that are using the full or bulk-logged recovery models.
You can use a log sequence number (LSN) to define the recovery point for a restore operation. However, this is a specialized feature that is intended for tools vendors and is unlikely to be generally useful.
LSNs are used internally during a RESTORE sequence to track the point in time to which data has been restored. When a backup is restored, the data is restored to the LSN corresponding to the point in time at which the backup was taken. Differential and log backups advance the restored database to a later time, which corresponds to a higher LSN. For more information about LSNs, see the SQL Server Transaction Log Architecture and Management Guide.
Note
LSNs are values of data type numeric(25,0). Arithmetic operations (for example, addition or subtraction) are not meaningful and must not be used with LSNs.
The LSN of a log record at which a given backup and restore event occurred is viewable using one or more of the following:
Note
LSNs also appear in some messages in the error log.
By using a RESTORE statement, you can stop at or immediately before the LSN, as follows:
-
Use the WITH STOPATMARK ='lsn:<lsn_number>' clause, where lsn:<lsnNumber> is a string that specifies that the log record that contains the specified LSN is the recovery point.
STOPATMARK roll forwards to the LSN and includes that log record in the roll forward.
-
Use the WITH STOPBEFOREMARK ='lsn:<lsn_number>' clause, where lsn:<lsnNumber> is a string that specifies that the log record immediately before the log record that contains the specified LSN number is the recovery point.
STOPBEFOREMARK rolls forward to the LSN and excludes that log record from the roll forward.
Typically, a specific transaction is selected to be included or excluded. Although not required, in practice, the specified log record is a transaction-commit record.
The following example assumes that the AdventureWorks
database has been changed to use the full recovery model.
RESTORE LOG AdventureWorks FROM DISK = 'c:\adventureworks_log.bak'
WITH STOPATMARK = 'lsn:15000000040000037'
GO
-
Restore a Database to the Point of Failure Under the Full Recovery Model (Transact-SQL)
-
Restore a Database to a Marked Transaction (SQL Server Management Studio)
-
Restore a SQL Server Database to a Point in Time (Full Recovery Model)
Apply Transaction Log Backups (SQL Server)
The Transaction Log (SQL Server)
RESTORE (Transact-SQL)
Restore and Recovery Overview (SQL Server)
SQL Server Transaction Log Architecture and Management Guide