UNIT - 3 Dbms
UNIT - 3 Dbms
UNIT - 3 Dbms
TRANSACTIONS
Transaction Concepts
• A transaction can be defined as a group of tasks that form a
single logical unit
• Collection of operations that form a single logical unit of work.
Eg: Withdraw Rs. 100 from an account then the following
operations are:
1. Check account balance
2. If sufficient balance is present request for withdrawal
3. Get the money
4. Calculate Balance = Balance – 100
5. Update account with new balance
• The transaction consists of all operations executed between the
begin transaction and end transaction
• In database, each transaction should maintain ACID property
to meet the consistency and integrity of the database
• Two main issues to deal with:
– Failures of various kinds, such as hardware and system
crashes
– Concurrent execution of multiple transactions
Transaction processing system:
– The system with large database and hundreds of concurrent users
that are executing database transaction.
– Eg :reservation system , banking system etc
Concurrent access
• Multiple user accessing a system at the same time
Single user - one user at a time can use a system
Multi user - many user use the system at a time. It can be achieved by
multiprogramming:
• Parallel - multi-users access different resources at the same time.
• Interleaved - Multiple users access a single resource based on time.
Transaction access data using two operations
Read(x)
• It transfer the data item x from the database to a local buffer belonging to
the transaction that executed the read operation.
Write(x)
• It transfer the data item x from the local buffer of the transaction to the
database i.e. it write back to the database.
ACID Properties
• To ensure the integrity of data during a transaction, the database system maintains
the following properties.
• These properties are widely known as ACID properties: A – Atomicity
C – Consistency
I – Isolation
D - Durability
1. Atomicity
• This property states that each transaction must be considered
as a single unit and must be completed fully or not
completed at all
• No transaction in the database is left half completed
• Database should be in a state either before the transaction
execution or after the transaction execution. It should not be
in a state ‘executing’
• Maintained by Transaction Management Component
2. Consistency
• Consistency stands for correctness
• This property ensures that any transaction will bring the database from valid state to
another
• The database must remain in consistent state after performing any transaction
• Responsibility of Application Programmer
3. Isolation
• More than one transaction are being executed simultaneously and in parallel
• No transaction will affect the existence of any other transaction
• Ensures that concurrent execution results in a system state that would be obtained if
transaction would be executed serially
• Managed by Concurrency Control Manager
4. Durability
• The database should be strong enough to handle any system failure
• Changes should be permanent
• The changes must NOT be lost due to some database failure
• If there is any set of insert/update, then it should be able to handle and commit to the
database
• If there is any failure, the database should be able to recover it to consistent state
• Responsibility of Recovery Manager
Transaction States
Contd…
• A transaction must be in one of the following states:
• Advantages:
– Increased processor and disk utilization
– Reduced average response time
Schedules
• Schedule is an order of multiple transactions executing in concurrent environment
• Sequences that indicate the chronological order in which instructions of concurrent
transactions are executed
– A schedule for a set of transactions must consist of all instructions of those
transactions
– Must preserve the order in which the instructions appear in each individual
transaction
Types of Schedule
Schedule
Conflict View
Contd…
• Serial Schedule: The schedule in which the transactions
execute one after the other. It is consistent in nature.
Eg: T1 T2
R(A)
W(A)
R(B)
W(B)
R(A)
W(A)
R(B)
W(B)
• Non Serial Schedule: The schedule in which operations present
within the transaction are intermixed. This may lead to conflicts
in the result or inconsistency in the resultant data
Eg:
T1 T2
R(A)
W(A)
R(A)
W(B)
R(A)
W(B)
R(B)
W(B)
Schedule 1 (T1 is followed by T2)
Schedule 2 (T2 is followed by T1)
Schedule 3 (Equivalent to Schedule T1)
– [ Begin transaction ,T ]
– [ write_item , T, X , oldvalue,newvalue]
– [read_item,T,X]
– [commit,T]
– [abort,T]
DEADLOCK