DBMS - Transaction Management
DBMS - Transaction Management
of
Transaction Management
Chapter8 (part-1): Overview of Transaction
Management (T2:Page 519-540, 550-555)
1. Atomicity
2. Consistency
3. Isolation
4. Durability
Atomicity
Users should be able to regard the execution of
each transaction as atomic: either all actions are
carried out or none are.
A transaction is an atomic unit of processing; it is
either performed in its entirety or not performed at
all.
Users should not have to worry about the effect of
incomplete transactions (when a system crash
occurs).
The system should ensure that updates of a
partially executed transaction are not reflected in
the database
Atomicity
Transactions can be incomplete for three kinds of
reasons:
The system may crash
A transaction can be aborted, or terminated by
DBMS
A transaction may encounter an unexpected
situation and decide to abort
Thus a DBMS must find a way to remove the effects
of partial transactions from the database, that is, it
must ensure transaction atomicity: either all of a
transaction's actions are carried out, or none are.
Consistency
Serial schedule
If the actions of different
transactions are not interleaved i.e.
transactions are executed from
start to finish, one by one ,
schedule is serial.
Basic Assumption is each
transaction preserves database
consistency.
Thus serial execution of a set of
transactions preserves database
consistency.
Transactions and Schedules
This schedule is
not a serial
schedule, but it is
equivalent to
Schedule T1;T2.
Serializability (Example)
Serializability (Example)
This concurrent
schedule does not
preserve the value
of (A + B ).
Anomalies Due to Interleaved Execution
This definition of
serializability relies on the
actions of aborted
transactions being undone
completely, which may be
impossible in some
situations.
Schedules Involving Aborted Transactions
The actions of
different transactions
can be interleaved if
lock is sharable.
Deadlocks
Example:
Transaction T1 sets an exclusive lock on object A,
T2 sets an exclusive lock on B, T1 requests an
exclusive lock on B and is queued, and T2 requests
an exclusive lock on A and is queued.
T1 waiting for T2 to release its lock and T2 is
waiting for T1 to release its locks.
Such a cycle of transactions waiting for locks to be
released is called as Deadlock.
These two transactions will make no further
progress.
Deadlocks
1. savepoint:
savepoint allows us to identify a point in a
transaction and selectively roll back operations
carried out after this point.
This is especially useful if the transaction carries
out what-if kinds of operations and wishes to undo
or keep the changes based on the results.
In a long running transaction, a series of
savepoints can be defined.
Transaction support in SQL
2. Chained transaction:
Even with the use of savepoints, certain
applications might require us to run several
transactions one after the other.
To minimize, the overhead in such situations, SQL:
1999 introduces another feature, called chained
transactions.
We can commit or rollback a transaction and
immediately initiate another transaction. This is
done by using the optional key words AND CHAIN
in the COMMIT and ROLLBACK statements.
What Should We Lock?