As mentioned above , transaction is a unit of program execution in a database application that accesses and possibly updates various data items.
The database operations that form a transaction can either be embedded within an application program or they can be specified via high-level query language such as SQL.
A transaction is delimited by statements of the form begin transaction and end transaction.
Database is represented as a collection of data items which can be a field of some record or a record or even a whole disk block.
Access to database is accomplished by the following two operations:
- read(X) which transfers the data item X from the database to a local buffer belonging to the transaction that executed the read operation
- write(X) which transfers the data item X from the local buffer of the transaction that executed the write back to the database.
In the real database system, the write operation either immediately update the data on the disk or temporarily stored in the memory and executed on the disk later. For now, we assume that write operation updates the database immediately.
Example of a transaction Ti that transfer $50 from account A to account B
Ti : read (A);
A:= A - 50;
write (A);
read (B);
B:= B + 50;
write (B);
Transaction state
In the absence of failures, all transaction must always terminated. However, a transaction may not always complete its execution successfully. In that case, we have an unchanged database and the transaction is called aborted. A transaction can be in one of the following states during the execution:
- Active: This is the initial state, the transaction stays in this state while it is executing and it can issue READ, WRITE operation in this state
- Partially commited: after the final statements has been executed, transaction moves to this state.
- Committed: after successfully completion.
- Failed: after the discovery that normal execution can no longer proceed
- Aborted: after the transaction has been rolled back and the database has been restored to it state prior to the start of the transaction
![]() |
A transaction starts in the active state. When it finishs its final statement, it enter partially committed state. At this point, even the transaction has already completed all is statements, it may have still be aborted since the actual output may still be temporarily residing in main memory not yet be copied to the disk. A transaction is committed only if it has performed updates transforms the database into a consistent sate, which must be persist even if there is a system failure . A transaction is said to have terminated if either committed or aborted.
A transaction enter failed state after the system cannot process the transaction normal execution because of hardware or logical errors. Such transactions must be rolled back and enter aborted state. At this point, the system can do either restart the transaction or kill the transaction.
The system log
In order to recover the database from failures that affect transactions, the database system maintain a log file in which records all the operations that access the values of data items. A log record can be one of the following entries
- [start_transaction, T] where T is an unique transaction id
- [write, T, X, old_value, new_value] indicate a write operation in transaction T which changed the value of data item X from old-value to new_value
- [read, T, X] : transaction T read the data item X
- [commit, T] . T is commited
- [abort, T] T is aborted
This log file will be used to do recover of database system. We will discuss more about recovery later.
Commit Point of a Transaction
A transaction is at the commit point if all of its operations are successfully complete and the effects of all operations have been recorded in the log and performed in the database.
Beyond the commit point, the transction write record [commit, T] to the log. If a failure occure, all transactions with no commit record will have to be rolled back.









