Chap 5 Database Transaction Management
Chap 5 Database Transaction Management
DATABASE TRANSACTION
MANAGEMENT
• Isolated
– Data used during the execution of a database
transaction must not be used by another
database transaction until the execution is
completed.
• Durable
– Database changes are permanent after the
transaction completes.
START TRANSACTION and COMMIT
Lost Update
Lost updates occur when two or more
transactions select the same row and then
update the row based on the value originally
selected.
One user’s update overwrite another user’s update
The last update overwrites updates made by the other
transactions, which results in lost data.
INTEREFERENCE PROBLEM ARISE FROM
SIMULTANEOUS ACCESS TO DATABASE
• Transaction Log
– Transaction log records all transactions
and the database modifications made
by each transaction.
– A critical component of the database
and, if there is a system failure, the
transaction log might be required to
bring database back to a consistent
state.
RECOVERY TOOLS
• Transaction Log
– History of database changes
– Operations
• Undo: revert to previous state
• Redo: reestablish a new state
LSN TransNo Action Time Table Row Column Old New
1 101001 START 10:29
2 101001 UPDATE 10:30 Acct 10001 AcctBal 100 200
3 101001 UPDATE 10:30 Acct 15147 AcctBal 500 400
4 101001 INSERT 10:32 Hist 25045 * <1002,
500,
…>
5 101001 COMMIT 10:33
RECOVERY TOOLS
• Database Back-up
– Enables to back up and restore databases.
– Backup and restore component provides an important
safeguard for protecting critical data stored in Database.
– A copy of data that can be used to restore and recover
the data is called a backup. Backups can restore data
after a failure. With good backups, it can recover from
many failures, such as:
• Media failure.
• User errors, for example, dropping a table by mistake.
• Hardware failures, for example, a damaged disk drive or permanent loss
of a server.
• Natural disasters.
Database Recovery Management
• Database recovery
– Restores database from a given state, usually
inconsistent, to a previously consistent state
– Based on the atomic transaction property
• All portions of the transaction must be treated as a single
logical unit of work, in which all operations must be
applied and completed to produce a consistent database
– If transaction operation cannot be completed,
transaction must be aborted, and any changes to
the database must be rolled back (undone)
Transaction Recovery
• Write-through
– Database is immediately updated by transaction
operations during the transaction’s execution, even
before the transaction reaches its commit point
– If the transaction aborts before it reaches its commit
point, a ROLLBACK is done to restore the database to
a consistent state
• A transaction that committed after the last checkpoint is
redone using the “after” values of the log
• A transaction with a ROLLBACK after the last checkpoint is
rolled back using the “before” values in the log
A Transaction Log for Transaction Recovery Examples
Transaction Recovery Examples