Explain the log based recovery in DBMS

DBMSDatabaseBig Data Analytics

Log is nothing but a file which contains a sequence of records, each log record refers to a write operation. All the log records are recorded step by step in the log file. We can say, log files store the history of all updates activities.

Log contains start of transaction, transaction number, record number, old value, new value, end of transaction etc. For example, mini statements in bank ATMs.

If within an ongoing transaction, the system crashes, then by using log files, we can return back to the previous state as if nothing has happened to the database.

The log is kept on disk so that it is not affected by failures except disk and failures.

Example

Different types of log records are as follows −

  • <Ti, Xi, V1, V2> − update log record, where Ti=transaction, Xi=data, V1=old data, V2=new value.

  • <Ti, start> − Transaction Ti starts execution.

  • <Ti, commit> − Transaction Ti is committed.

  • <Ti, abort> − Transaction Ti is aborted

The log records can be written as follows −

Create a log for the given transaction T1 and T2.
  T1            T2              Log
 Read A        Read A        <T1, start>
 A=A-2000      A=A+5000     <T1,A,5000, 3000>
 Write A      Write A       <T1, B, 8000, 10000>
 Read B       Read B        <T1, commit>
 B=B+2000     B= B+7000     <T2, start>
 Write B      Write B      <T2, A, 3000, 8000>
                           <T2, B, 10000, 17000>
                           <T2, commit>

Log based recovery techniques

Log based recovery uses one of the techniques −

Deferred database modification

It modifies the database after completion of transaction. The database modification is deferred or delayed until the last operation of the transaction is executed. Update log records maintain the new value of the data item.

Recover system uses one operation which is as follows −

  • Redo(Ti) − All data items updated by the transaction Ti are set to a new value.

Immediate database modification

It modifies the database after a write operation, database modification is immediately done when a transaction performs an update/ write operation. Update log records maintain both old and new values of data items.

The recovery system uses two operations, which are as follows −

  • Undo(Ti) − All data items updated by the transaction Ti, are set to old value.

  • Redo(Ti) − All data items updated by the transaction Ti are set to a new value.

raja
Updated on 06-Jul-2021 15:01:08

Advertisements