Unit-6 SGM DBMS
Unit-6 SGM DBMS
TRANSACTION MANAGEMENT
Transaction: It is a program unit or logical unit whose
execution may change the content of database.
A Transaction can be accessed by using two Operations that
are read and write Operations.
For Example,In a Bank database initially ‘A’ has Rs.15000/-
and ‘B’ has Rs.11000/- suppose ‘A’ can be transferred
Rs.2000/- to ‘B’,the transaction can be done in following
way. i.e.,
A=15000 B=11000
R(A) R(B)
A=A-2000 B=B+2000
W(A) W(B)
13000/- 13000/-
IIIT,Ongole
• Each Trasaction is considered as 1 unit and either run to
completion (or) not executed at all..
Example:
A=15000 B=11000
R(A) R(B)
A=A-2000 B=B+2000
W(A) W(B)
13000/- 13000/-
2.Consistency:
• This means that Integrity Constraiant must be maintained.So
that database is Consistent before and after the transaction.
• Consistency also called as “Correctness Of Database”.
• For Example,The total amount before and after the
transaction must be maintained in consistent Mode. i.e.,
Example:
A=15000 B=11000
R(A) R(B)
A=A-2000 B=B+2000
W(A) W(B)
13000/- 13000/-
IIIT,Ongole
3.Isolation:
• This property describe that multiple Transaction can occur
concurrently without reading to inconsistency of database
state.
• Here One transaction can be occur independently with other
transaction.
• The Changes occur in a particular transaction will not affect
any other transaction.
• For every pair of Transaction,One transaction should start
execution only when other finish the execution.
4.Durability:
Once a Transaction Completed Successfully,the changes
made into the database should be permanent if there is a
system failure.
The Modification to the Databse once stored in and written to
the disk.if there is a system failure,the recovery management
components are recover the data.
Partially Committed
Committed
Active Terminated
Failed Aborted
IIIT,Ongole
(1)ACTIVE STATE:
• It is the first state of the transaction.
• A Transaction is enter into active state when execution
process begins.
• During the state read/write operations can be performed.
• For example,You can insert,delete,update record is done
here.But all the records are still not saved to the database.
(4)FAILED STATE:
• When a Transaction is getting executed in the partially
committed (or) active state and some failures occur due to
impossible to continue its execution That’s why it enter into
“Failed” State.
(5)ABORTED STATE:
• If one of the checks fails and the Transaction reached to
failed state and then goes to aborted state.
IIIT,Ongole
• If the Transaction fails in the middle of the Transaction then
before executing Transaction all the Transactions are rollback
to consistency State.
• After Abort the Transaction,the database recovery state can
select one of the following operation:
1.Restart the Transaction
2.Kill the Transaction
(6)TERMINATED STATE:
• It is Last state of the Life cycle of Transaction.
• After enter into committed state (or) Aborted state .The
Transaction finally enter into terminated state..
IIIT,Ongole
Example: Let us consider two Transactions T1 and T2 with
respective of time and X is data item.
T1 T2
Read(X)
X=X+10
R(X)
X=X-20
W(X)
W(X)
IIIT,Ongole
➢ Here uncommitted data occurs when two Transactions T1 and
T2 are executed concurrently and first Transaction T1 is
rollback after the second Transaction T2 has already accessed
the uncommitted data does violating the isolation property of
Transaction.
SCHEDULE IN DBMS:
**Schedule**:
• When Multiple transaction are running concurrently then
database goes in inconsistency state.
• Schedule is a process of sequence of operation done one after
another.
IIIT,Ongole
Example:
T1 T2
R(X)
W(X)
R(X)
W(X)
Types Of Schedules:
Schedule
Serial Non-Serial
Non-Serializability
Serializability
Conflict Recoverable
View
Non-Recoverable
IIIT,Ongole
Serializable Schedule:
• If a given Serial Schedule of ‘n’ transactions is equalent to
some Non-serial of ‘n’ transactions then it is called as
“Serializable Schedule”.
• It is behave same as “Serial Schedule”
• Concurrency is allowed that means multiple transaction can
execute concurrently.But it can improve both resource
utilization and high throughput.
Types of Serializability:
There are 2 types: 1.Conflict Serializability
2.View Serializability
1.Conflict Serializability:
A Serializability said to be conflict,it should satisfy following
conditions:
(1)Both the Operations belongs to different transaction.
(2)Both the Operations are works on same Data item.
(3)Atleast one of the Operation is write operation.
Example:
1. ( R1(A) ,W2(A) ) (True)
2. ( W1(A) ,W2(A) ) (True)
3. ( W1(A) ,R2(A) ) (True)
4. ( R1(A) ,W2(B) ) (False)
5. ( W1(A) ,W2(B) ) (False)
6. ( R1(A) ,R2(A) B ) (True)
FALSE
IIIT,Ongole
Example:
(1)R1(x),R2(x),W1(x),R1(y),W2(x),W1(y)
Sol:
T1 T2
R(X)
R(X) T1 T2
W(X)
R(Y)
W(X)
W(Y)
(2)
T1 T2 T3
R(A)
R(B)
R(A)
T1 T2
R(C)
W(B)
R(B)
R(C)
R(B) T3
W(A)
W(B)
2.View Serializability:
• A Serializability said to be view Serializability if it is
equivalent to serial schedule.
IIIT,Ongole
• If Schedule is conflict Schedule the it will be view
serializable but view serializability is not a conflict
serializability.
• Two Schedules S1 and S2 said to be view equivaleent
then it can be satisfy the following conditions..
(1)Initial read
(2)Updated read
(3)Finl read
(1)Initial read:
The initial read of both the schedules must be
same.Suppose two schedules s1 and s2,in schedule S1 if a
transaction it is read the data item x then in S2 the
Transaction T1 also read the data item x.
S1:
T1 T2
R(X)
W(X)
S2:
T1 T2
W(X)
R(X)
• In above example two schedules are equivalent initial
read operation is s1 is done by transaction T1 and S2 it
also done by transaction T1.
(2)Updated Read:
In Schedule S1 if Tj is reading x which is updated by Ti
then in S2 also.
IIIT,Ongole
S1:
T1 T2 T3
W(X)
W(X)
R(X)
S2:
T1 T2 T3
W(X)
W(X)
R(X)
• In above example two schedules are not view
equivalent because in s1,the Transaction T3 read(x)
updated by T2 and in schedule S2 the Transaction T3
read(x) updated by T1.
S1:
T1 T2 T3
W(X)
W(X)
R(X)
S2:
T1 T2 T3
W(X)
W(X)
W(X)
R(X)
IIIT,Ongole
(3)Final Write:
A final Write must be same between both the
schedules.In Schedule S1 if a transaction T3 update x at last
operation with write,In schedule S2 also.
S1:--
T1 T2 T3
R(A)
W(A)
W(A)
W(A)
S2:--
T1 T2 T3
R(A)
W(A)
W(A)
W(A)
It is View equivalent..
**Note**: With ‘n’ Transactions the total no.of schedules
are occurred that equal to “n!”.
Ex: With 3 transactions the total no.of schedules are
occured 3!=6.
S1: T1 T2 T3
S2: T1 T3 T2
S3: T2 T1 T3
S4: T2 T3 T1
S5: T3 T1 T2
S6: T3 T2 T1
IIIT,Ongole
Recoverability in Schedule:
If some transactions Tj is reading the values that can be
updated (or) written by some other transactions Ti,then
commit of Tj must be occur after the commit of Ti it is
called “Recoverability”
Ti Tj
R(A)
W(A)
W(A)
R(A)
commit
commit
Irrecoverability:
The schedule is said to be irrecoverable if Tj read the
Updated (or) written by Ti and Tj commits before Ti
commit.
Ti Tj
R(A)
W(A)
W(A)
R(A)
commit
commit
IIIT,Ongole