When do we use undo and redo operations in a database recovery? For instance, consider the following questions asked in an exam (not a homework)
Consider the following log sequence of two transactions on a bank account: With an initial balance of 12000, transfer 2000 to a mortgage payment and then apply a 5% interest.
Suppose the database system crashes just before log record 7 is written. When the system is restarted, which transactions undergo undo and redo operations?
All I know here is that if the system crashes right after the commit is written to the log and before flushing the buffer to secondary storage, we need to redo those transactions. But here the system crashes before writing the log entry for the commit. So if we undo records 2 and 3, will it be enough?
If the database crashes at point 7, everything until point 4 (including) is already on disk. That is the guarantee that commit gives (assuming no special features like async commit are used).
During recovery basically the state after point 4 is restored.