DBMS Unit 4
DBMS Unit 4
Read(X): Read operation is used to read the value of X from the database and stores it in a buffer
in main memory.
Write(X): Write operation is used to write the value back to the database from the buffer.
Let's take an example to debit transaction from an account which consists of following
operations:
• It states that all operations of the transaction take place at once if not, the transaction is aborted.
• There is no midway, i.e., the transaction cannot occur partially. Each transaction is treated as one
unit and either run to completion or is not executed at all.
Read(A) Read(B)
A:= A-100 Y:= Y+100
Write(A) Write(B)
After completion of the transaction, A consists of Rs 500 and B consists of Rs 400.
If the transaction T fails after the completion of transaction T1 but before completion of transaction T2, then the amount
will be deducted from A but not added to B. This shows the inconsistent database state. In order to ensure correctness of
database state, the transaction must be executed in entirety.
By Ajai Kumar Maurya CSE Mob: 9335833415
Consistency
• The integrity constraints are maintained so that the database is consistent
before and after the transaction.
• The execution of a transaction will leave a database in either its prior stable
state or a new stable state.
• The consistent property of database states that every transaction sees a
consistent database instance.
• The transaction is used to transform the database from one consistent state
to another consistent state.
For example: The total amount must be maintained before or after the transaction.
1.Total before T occurs = 600+300=900
2.Total after T occurs= 500+400=900
Therefore, the database is consistent. In the case when T1 is completed but T2 fails, then inconsistency will occur
By Ajai Kumar Maurya CSE Mob: 9335833415
Isolation
• It shows that the data which is used at the time of execution of a transaction cannot be used by the
• In isolation, if the transaction T1 is being executed and using the data item X, then that data item can't be
• The concurrency control subsystem of the DBMS enforced the isolation property.
❖ The active state is the first state of every transaction. In this state, the
❖ For example: Insertion or deletion or updating a record is done here. But all the
Partially committed
❖ In the partially committed state, a transaction executes its final operation, but the data is still not saved to
the database.
❖ In the total mark calculation example, a final display of the total marks step is executed in this state.
this state, all the effects are now permanently saved on the database system.
Failed state
❖ If any of the checks made by the database recovery system fails, then the transaction is
❖ In the example of total mark calculation, if the database is not able to fire a query to fetch
❖ It can restart the transaction, but only if the transaction was aborted as a result of some
hardware or software error that was not created through the internal logic of the transaction. A
❖ It can kill the transaction. It usually does so because of some internal logical error that can be
corrected only by rewriting the application program, or because the input was bad, or because
transaction.
3. Serializable schedule
• The serializability of schedules is used to find non-serial schedules that allow the transaction to execute
concurrently without interfering with one another.
• It identifies which schedules are correct when executions of the transaction have interleaving of their
operations.
• A non-serial schedule will be serializable if its result is equal to the result of its transactions executed
serially.
conflicting instructions.
or not.
Solution:
(1) Clearly schedule-1 and schedule-2 are serial schedules, therefore these schedules are conflict
serializable
By Ajai Kumar Maurya CSE Mob: 9335833415
•If a precedence graph contains a single edge Ti →
Tj, then all the instructions of Ti are executed
before the first instruction of Tj is executed.
•If a precedence graph for schedule S contains a
cycle, then S is non-serializable. If the precedence
graph has no cycle, then S is known as serializable.
The precedence graph for schedule S2 contains no cycle that's why ScheduleS2 is serializable.
T1 T2
Read(A)
Write(A)
Read(B)
Write(B)
Read(A)
Write(A)
Read(B)
Write(B) Since, S1 is conflict serializable.
View Equivalent
Two schedules S1 and S2 are said to be view equivalent if they
satisfy the following conditions:
Above two schedules are not view equal because, in S1, T3 is reading A updated by T2
and in S2, T3 is reading A updated by T1.
and that value is read and written by T2. T2 commits but later on, T1 fails. Due to the failure, we
have to rollback T1. T2 should also be rollback because it reads the value written by T1, but T2 can't
schedule.
The above table 2 shows a schedule with two transactions. Transaction T1 reads and writes A, and that value is
read and written by transaction T2. But later on, T1 fails. Due to this, we have to rollback T1. T2 should be
rollback because T2 has read the value written by T1. As it has not committed before T1 commits so we can
rollback transaction T2 as well. So it is recoverable with cascade rollback.
The above Table 3 shows a schedule with two transactions. Transaction T1 reads and write A and
commits, and that value is read and written by T2. So this is a cascade less recoverable schedule.
Failure
one another to give up locks. Deadlock is said to be one of the most feared
complications in DBMS as no task ever gets finished and is in waiting state forever.
For example: In the student table, transaction T1 holds a lock on some rows and needs
to update some rows in the grade table. Simultaneously, transaction T2 holds locks on
some rows in the grade table and needs to update the rows in the Student table held
by Transaction T1.
• When a database is stuck in a deadlock state, then it is better to avoid the database rather than
aborting or restating the database. This is a waste of time and resource.
• Deadlock avoidance mechanism is used to detect any deadlock situation in advance. A method
like "wait for graph" is used for detecting the deadlock situation but this method is suitable only
for the smaller database. For the larger database, deadlock prevention method can be used.
Deadlock Detection
In a database, when a transaction waits indefinitely to obtain a lock, then the DBMS should detect whether the
transaction is involved in a deadlock or not. The lock manager maintains a Wait for the graph to detect the
deadlock cycle in the database.