Getting Started with Adobe After Effects - Part 6: Motion Blur
First Time? You can support us by signing up. It takes only 5 seconds. Click here to sign up. If you already have an account, click here to login.
Loading

1st Prize - Apple iPad


SQLServer Quiz 2011 - What is the impact of an open transaction with the LSN Sequence captured during a full backup ?

  • Backup is a consistency operation with SQL Server that means the engine should capture a piece of the log during backup. When we use the command RESTORE HEADERONLY or ask the backupset table in msdb database we can see information related to the LSN sequence like DatabaseBackupLSN, CheckpointLSN, FirstLSN and LastLSN.

    When an open transaction is issued before a backup operation what is the consequence of these LSN informations catched into it ?

    Posted on 09-27-2011 00:00 |
    David Barbarin
    201 · 1% · 230

7  Answers  

Subscribe to Notifications
  • Score
    10

    If the backup only contained the log that occured while the database was being backed up, how would it roll back the active transaction. It has to include enough transaction log to roll back the active transaction. The start LSN of the log included in a database backup is the minimum of:

    • LSN of the last checkpoint
    • LSN of the start of the oldest active transaction
    • LSN of the last replicated transaction
    Database_Backup_Lsn   		(54:68:37)  
      First_Lsn 					  (54:118:1)  
      CheckPoint_LSN    			     (54:124:148)
      Last_Lsn  					   (54:185:1)
      

    you can see the checkpoint that begins the backup was at (54:124:148). The LSN of the first log record that the backup contains is (54:118:1), which is before the start of the backup.And the backup contains all the log from then until (54:185:1)

    if you check using

    SELECT [Current LSN], Operation, [Transaction Name] FROM fn_dblog (null,null);
    

    it will show first log record (54:118:1) it will show user_transaction in Transaction Name Field

    http://www.sqlskills.com/blogs/paul/post/Debunking-a-couple-of-myths-around-full-database-backups.aspx

    Replied on Sep 27 2011 8:14AM  . 
    Mitesh Modi
    18 · 10% · 3078
  • Score
    10

    The DatabaseBackupLSN is the log sequence number of the most recent full database backup. If we compare new and previous full database backup we can see that DatabaseBackupLSN of the new backup is same as CheckpointLSN of the old full database backup.

    CheckpointLSN is the log sequence number of log record when backup operation take a checkpoint to force all dirty pages in the buffer pool to disk (from committed and uncommitted transaction).

    The FirstLSN value is the log sequence number of the first transaction in the backup. If database is idle FirstLSN and CheckpointLSN will be the same (if there is no replication).

    The LastLSN value is the log sequence number of the last transaction in the backup. It's greater then FirstLSN and CheckpointLSN.

    When an open transaction is issued before a backup operation what is the consequence of these LSN informations catched into it ?

    An open transaction which is issued before a backup operation has no effect on the DatabaseBackupLSN and LastLSN. These values will be the same if an transaction is issued before or after a backup operation start.

    FirstLSN will contain LSN of an open transaction.

    CheckpointLSN will contain LSN of an backup checkpoint and it will be greater than FirstLSN.

    Replied on Sep 28 2011 4:19PM  . 
    Ana
    119 · 1% · 430
  • Score
    5

    When we use the command RESTORE HEADERONLY ?

    RESTORE HEADERONLY looks at all backup sets on the media. Therefore, producing this result set when using high-capacity tape drives can take some time. To get a quick look at the media without getting information about every backup set, use RESTORE LABELONLY or specify FILE = backupsetfile_number.

    RESTORE HEADERONLY FROM DISK = N'C:\AdventureWorks2008R2-FullBackup.bak' WITH NOUNLOAD; GO

    for each backup on given device server send a row of header information, explaining the terms as given below FirstLSN numeric(25,0) Log sequence number of the first log record in the backup set. NULL

    LastLSN numeric(25,0) Log sequence number of the next log record after the backup set. NULL

    CheckpointLSN numeric(25,0) Log sequence number of the most recent checkpoint at the time the backup was created. NULL

    DatabaseBackupLSN numeric(25,0) Log sequence number of the most recent full database backup.

    DatabaseBackupLSN is the “begin of checkpoint” that is triggered when the backup starts. This LSN will coincide with FirstLSN if the backup is taken when the database is idle and no replication is configured. NULL

    Replied on Oct 2 2011 3:10AM  . 
    Manoj Bhadiyadra
    153 · 1% · 315
  • Score
    10

    Each transaction log record is identified by a log sequence number (LSN). Each new log record is written to the logical end of the log with an LSN that is higher than the LSN of the record before it.Log sequence numbers, or LSN, are assigned to each record in the transaction log.When you perform a backup, certain LSN values are stored both in the file itself, and in the msdb..backupset table. You can retrieve the LSN values from a backup file using the RESTORE HEADERONLY syntax.

    The FirstLSN value is the log sequence number of the first transaction in the backup set. The LastLSN value is the log sequence number of the last transaction in the backup set. The CheckpointLSN value is the log sequence number of the most recent checkpoint. The DatabaseBackupLSN is the log sequence number of the most recent full database backup.

    A transaction log back up need to be restored in sequence.The file that need to be restored next must have a LSN value that matches the LastLSN value of the previous restored file. For a transaction log backup, the FirstLSN and LastLSN values help us to sort the transaction log files in sequence, during a restore process.

    If database is idle FirstLSN and CheckpointLSN will be the same .The LastLSN value is the log sequence number of the last transaction in the backup. It will be greater then FirstLSN and CheckpointLSN.

    If transaction started before backup nothing will be happened to DatabaseBackupLSN and LastLSN. FirstLSN will contain LSN of an open transaction. CheckpointLSN will contain LSN of an backup checkpoint and it will be greater than FirstLSN.

    Replied on Oct 13 2011 8:15AM  . 
    Sineetha
    105 · 2% · 492
  • Score
    10

    The FirstLSN value is the log sequence number of the first transaction in the backup set. The LastLSN value is the log sequence number of the last transaction in the the backup set. The CheckpointLSN value is the log sequence number of the most recent checkpoint. The DatabaseBackupLSN is the log sequence number of the most recent full database backup.

    Considering the case where there's an active transaction that doesn't commit and, ofcourse, the transaction Started before the backup operation started, following will be the cases with each;

    DatabaseBackupLSN: No impact of open transactoin. It wil behave normally. It will have the log sequence number of the most recent full database backup.

    LastLSN: No impact of open transactoin.

    FirstLSN: It will be having the LSN of the Open Transaction

    CheckpointLSN: It will be having the LSN of the database backup checkpoint and it will be greater than the FirstLSN

    For more internal workaround, check here

    Replied on Oct 18 2011 11:58PM  . 
    ATif-ullah Sheikh
    129 · 1% · 391
  • Score
    10

    This is another excellent question. This question actually covers the myth of a full database backup only contains the transaction log from the start of the backup to the end of the backup.

    Backupset table in msdb database has many columns that contain the details of the database backup. Following are the columns that are of interest for this quiz.

    First_LSN: It is the log sequence number of the first or oldest log record in the backup set. . If database is idle FirstLSN and CheckpointLSN will be the same. It contains the LSN of an open transaction.

    LastLSN: It is the log sequence number of the next log record after the backup set. This value is greater than FirstLSN and Checkpoint_LSN.

    CheckpointLSN: It is the log sequence of the log record where the redo must start. It will contain the LSN of a backup check point, and this value will be greater than FirstLSN.

    Databasebackuplsn: It is the log sequence number of the most recent full database backup. When we compare new and previous full database backup we can see that DatabaseBackupLSN of the new backup is same as Checkpoint_LSN of the old full database backup.

    An open transaction which is issued before a backup operation has no effect on the DatabaseBackupLSN and Last_LSN. These values will be the same if a transaction is issued before or after a backup operation start.

    Basically, when we restore a full database backup, we get a transitionally consistent database. In the case where there is an active transaction that does not commit until after the backup completes, if the backup only contained the log occurred while the database is being backed up, how would it roll back the active transaction. This includes enough transaction logs to roll back the active transaction.

    The start of the LSN of the log included in a database backup is the minimum of the following items:

    • LSN of the last checkpoint
    • LSN of the start of the oldest active transaction
    • LSN of the last replicated transaction

    Let us demonstrate this with an example.

    1. Create a database SQLDBAQUIZ2011
    2. Place the database into Full Reocovery mode.
    3. Start a transaction without a commit.
    4. Checkpoint
    5. Take a backup of the SQLQUIZ2011.

    The checkpoint command makes sure that the paget that is going to be altered will be flushed to the disk and gets hardened there.

    CREATE DATABASE SQLQUIZ2011;
    GO
    ALTER DATABASE SQLQUIZ2011 SET RECOVERY FULL;
    GO
    BACKUP DATABASE SQLQUIZ2011 
    TO DISK = 'D:\SQLBackups\sqlquiz2011db.bak' WITH INIT;
    GO
    USE SQLQUIZ2011;
    GO
    CREATE TABLE Quiz27 ( quiz_id INT);
    GO
    BEGIN TRAN;
    INSERT INTO Quiz27 VALUES (1);
    GO
    

    Now in another Query analyzer with a new connection, let us take a full database backup.

    BACKUP DATABASE SQLQUIZ2011 
    TO DISK = 'D:\SQLBackups\sqlquiz2011db.bak' WITH INIT;
    GO
    

    The msdb.dbo.backupset table from the msdb database will tell us the relevant LSNs in the backup as shown below:

    SELECT first_lsn, last_lsn, checkpoint_lsn, database_backup_lsn 
    FROM msdb.dbo.backupset
    WHERE database_name = 'SQLQUIZ2011';
    GO
    

    We can see from the figure shown below that the checkpoint that begins the backup was at (37:101:148). The log sequence number (LSN) of the first log record the backup contains is (37:55:64) and this is before the start of the SQLQUIZ2011 database backup. So the backup contains the entire log from then until (37:162:01).

    Result of the Above Query: Figure 1

    Now let us analyze and look at the actual transaction log records to see what the LSNs correspond to using the following query:

    SELECT [Current LSN], Operation, [Transaction Name] 
    FROM fn_dblog (null,null);
    GO
    

    From the query we get the current LSN, operation details and the transaction name. Since the output is huge, and I am not adding here,if you want to test, you can use the above demo to see the output.

    Output of the above query shows that the backup contains more than just the log from the time the backup was running.

    So, there will be no impact of an open transaction for backup. The transaction will be rolled back if the restore sequence ends with restoring that backup.

    Replied on Oct 21 2011 8:39PM  . 

    0 · 0% · 0
  • Score
    10

    If the backup only contained the log that occured while the database was being backed up, how would it roll back the active transaction. It has to include enough transaction log to roll back the active transaction.

    One piece of information recorded in the checkpoint is the log sequence number (LSN) of the first log record that must be present for a successful database-wide rollback. This LSN is called the Minimum Recovery LSN (FirstLSN)

    LSN of the last checkpoint
    LSN of the start of the oldest active transaction
    LSN of the last replicated transaction

    When an open transaction is issued before a backup operation

    before execute query from msdb.dbo.backupset we understand columns on that table
    FirstLSN : For log backups, the first LSN identifies the first log record included in the backup.
    Last
    LSN : For log backups, includes log records up to but not including this LSN.
    if we have taken backup two time let say for one time we call A and for second time we call B so. BackupA.lastlsn >= BackupB.firstlsn.
    CheckpointLSN : Log sequence number of the most recent checkpoint at the time the backup was created.
    Database
    backup_lsn: It is the log sequence number of the most recent full database backup.

      SELECT first_lsn,last_lsn, checkpoint_lsn, database_backup_lsn FROM msdb.dbo.backupset
      WHERE database_name = 'LsnTest';
    
      Database_Backup_Lsn       	  (54:68:37)  
      First_Lsn     				  (54:118:1)  
      CheckPoint_LSN        		  (54:124:148)
      Last_Lsn      				  (54:185:1)
    

    Here checkpointLSN (54:124:148) is greater than FirstLsn(54:118:1). If database is idle FirstLSN and CheckpointLSN will be the same (if there is no replication).

    if you analysis transaction log Current LSN record = (54:118:1) and Transaction Name ="user_transaction"

    SELECT [Current LSN], Operation, [Transaction Name] FROM fn_dblog (null,null);
    

    In short If transaction started before backup then it has no effect on the DatabaseBackupLSN and Last_LSN. It will affeft the First LSN. For the ideal system FirstLSN and CheckpointLSN will be the same (if there is no replication).but due to open transaction FirstLSN will contain LSN of an open transaction LSN Number.

    http://www.sqlskills.com/blogs/paul/post/Debunking-a-couple-of-myths-around-full-database-backups.aspx

    Replied on Oct 22 2011 5:02AM  . 
    Mitesh Modi
    18 · 10% · 3078

Your Answer


Sign Up or Login to post an answer.
Please note that your answer will not be considered as part of the contest because the competition is over. You can still post an answer to share your knowledge with the community.

Copyright © Rivera Informatic Private Ltd.