Unit 4 DBMS Transcation
Unit 4 DBMS Transcation
The transaction consists of all operations executed between the begin transaction
and end transaction.
Operations of transaction:
1. Read Operation-
read_item(X). Reads a database item named X into a program variable. To simplify
our notation, we assume that the program variable is also named X.
2. Write Operation-
write_item(X). Writes the value of program variable X into the database item named
X.
Transaction States
A transaction in a database can be in one of the following states –
1. Active − In this state, the transaction is being executed. This is the initial state of
every transaction.
2. Partially Committed − When a transaction executes its final operation, it is said to be
in a partially committed state.
3. Failed − A transaction is said to be in a failed state if any of the checks made by the
database recovery system fails. A failed transaction can no longer proceed further.
4. Aborted − If any of the checks fails and the transaction has reached a failed state,
then the recovery manager rolls back all its write operations on the database to
bring the database back to its original state where it was prior to the execution of
the transaction. Transactions in this state are called aborted. The database recovery
module can select one of the two operations after a transaction aborts −
2. Temporary Update or Dirty Read Problem(Write Read Conflict). Reading the data
written by an uncommitted transaction is called as dirty read.
Schedules in DBMS: The order in which the operations of multiple transactions appear for
execution is called as a schedule.
The execution sequences in chronological order are called schedules.
The schedules are serial; each serial schedule consists of a sequence of instructions from
various transactions.
Types of Schedules
Serial Schedules-
All the transactions execute serially one after the other.
When one transaction executes, no other transaction is allowed to execute.
Schedules in which the transactions are executed non-interleaved, i.e., a serial schedule
is one in which no transaction starts until a running transaction has ended are called
serial schedules.
The serial schedule is a type of schedule where one transaction is executed completely
before starting another transaction.
Types of Serializability-
Serializability is mainly of two types-
1. Conflict Serializability
2. View Serializability
Conflict Serializability-
If a given non-serial schedule can be converted into a serial schedule by swapping its non-
conflicting operations, then it is called as a conflict serializable schedule.
Instructions li and lj of transactions Ti and Tj respectively, conflict if and only if there exists
some item Q accessed by both li and lj, and at least one of these instructions wrote Q.
Conflicting Operations-
Two operations are called as conflicting operations if all the following conditions hold true
for them-
Q2.Check whether the given schedule S is conflict serializable and recoverable or not?
Step-01:
List all the conflicting operations and determine the dependency between the transactions-
View Serializability
o A schedule will view serializable if it is view equivalent to a serial schedule.
o If a schedule is conflict serializable, then it will be view serializable.
o The view serializable which does not conflict serializable contains blind writes.
View Equivalent
Two schedules S1 and S2 are said to be view equivalent if they satisfy the following
conditions:
1. Initial Read
An initial read of both schedules must be the same. Suppose two schedule S1 and S2. In
schedule S1, if a transaction T1 is reading the data item A, then in S2, transaction T1 should
also read A.
2. Updated Read
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.
3. Final Write
Two schedules is view equal because Final write operation in S1 is done by T3 and in S2,
the final write operation is also done by T3
T1
T2
T3
1.The initial read operation in S is done by T1 and in S1, it is also done by T1.
2. In both schedules S and S1, there is no write read except the initial read that’s why we
don’t need to check that condition.
3.The final write operation in S is done by T3 and in S1, it is also done by T3. So, S and S1
are view Equivalent.The first schedule S1 satisfies all three conditions, so we don’t need to
check another schedule. Hence, view equivalent serial schedule is
T1 → T2 → T3
So, let us check whether the given schedule is conflict serializable or not.
Checking Whether S is Conflict Serializable Or Not-
Step-01:
List all the conflicting operations and determine the dependency between the transactions-
there exists no cycle in the precedence graph.Therefore, the given schedule S is conflict
serializable.
Thus, we conclude that the given schedule is also view serializable.
Q3. Check whether the given schedule S is view serializable or not?
Solution-
So, let us check whether the given schedule is conflict serializable or not.
Checking Whether S is Conflict Serializable Or Not-
Step-01:
List all the conflicting operations and determine the dependency between the transactions-
Clearly, there exists a cycle between T1 and T3 in the precedence graph.Therefore, the
given schedule S is not conflict serializable.
Since, the given schedule S is not conflict serializable, so, it may or may not be view
serializable.
there exists a cycle in the dependency graph. Thus, we conclude that the given schedule S
is not view serializable.
Non-Serializable Schedules-
A non-serial schedule which is not serializable is called as a non-serializable schedule.
A non-serializable schedule is not guaranteed to produce the the same effect as produced
by some serial schedule on any consistent database.
i) Recoverable Schedule
Recoverable Schedule:
if some transaction T j is reading value updated or written by some other transaction T i,
then the commit of T j must occur after the commit of T i.
If in a schedule,
The commit operation of the transaction that performs the dirty read is delayed.
This ensures that it still has a chance to recover if the uncommitted transaction fails
later.
Example 1:-
Example 2 - S1: R1(x), W1(x), R2(x), R1(y),R2(y), W2(x), W1(y), C1, C2;
Given schedule follows order of Ti->Tj => C1->C2. Transaction T1 is executed before T2
hence there is no chances of conflict occur. transaction T1 is committed before T2 i.e.
completion of first transaction performed first update on data item x, hence given
schedule is recoverable.
Example: Consider the following schedule involving two transactions T1 and T2.
T1 T2
R(A)
W(A)
W(A)
Commit
R(A)
Commit
This schedule is cascadeless. Since the updated value of A is read by T2 only after the
updating transaction i.e. T1 commits.
R(A)
R(A)
W(A)
Commit
W(A)
R(A)
commit
This is a strict schedule since T2 reads and writes A which is written by T1 only after the
commit of T1.
Transaction failure
Transaction failure :
System crash: a power failure or other hardware or software failure causes the
system to crash.
Disk failure: a head crash or similar disk failure destroys all or part of disk storage
2. Shadow paging
3.Checkpoint
A log is the most widely used recording database modification technique. The log is a
structure used for recording database modification. It is a sequence of log record recording
all the update activities in the database. There are many types of log record we denote the
various types of log records:
Shadow Paging
Shadow paging is one of the techniques that is used to recover from failure. We all know
that recovery means to get back the information, which is lost. It helps to maintain
database consistency in case of failure.
Shadow Paging is recovery technique that is used to recover database. In this recovery
technique, database is considered as made up of fixed size of logical units of storage
which are referred as pages. pages are mapped into physical blocks of storage, with help
of the page table which allow one entry for each logical page of database. This method
uses two page tables named current page table and shadow page table.
The entries which are present in current page table are used to point to most recent
database pages on disk. Another table i.e., Shadow page table is used when the
transaction starts which is copying current page table. After this, shadow page table gets
saved on disk and current page table is going to be used for transaction. Entries present
in current page table may be changed during execution but in shadow page table it never
get changed. After transaction, both tables become identical.
Advantages of shadow paging
The advantages of shadow paging are as follows −
Recovery
When a system with concurrent transactions crashes and recovers, it behaves in the
following manner −
The recovery system reads the logs backwards from the end to the last checkpoint.
It maintains two lists, an undo-list and a redo-list.
If the recovery system sees a log with <T n, Start> and <Tn, Commit> or just <Tn,
Commit>, it puts the transaction in the redo-list.
If the recovery system sees a log with <T n, Start> but no commit or abort log found,
it puts the transaction in undo-list.
All the transactions in the undo-list are then undone and their logs are removed. All the
transactions in the redo-list and their previous logs are removed and then redone before
saving their logs.
Deadlock Handling:-
A system is said to be in deadlock state when in set of transactions every transaction is
waiting for another transaction to finish its operation.
A deadlock is an unwanted situation in which two or more transactions are waiting
indefinitely for one another to give up locks.
Deadlock Occurs when each transaction T in a set is waiting for some item locked by some
other transaction T’. Both transactions stuck in a waiting queue.
Deadlock detection
Deadlocks can be described as a wait-for graph, which consists of a pair G = (V,E),
V is a set of vertices (all the transactions in the system) ! E is a set of edges; each
element is an ordered pair Ti →Tj.
If Ti → Tj is in E, then there is a directed edge from Ti to Tj, implying that Ti is waiting
for Tj to release a data item.
When Ti requests a data item currently being held by Tj, then the edge Ti Tj is
inserted in the wait-for graph. This edge is removed only when Tj is no longer
holding a data item needed by Ti
The system is in a deadlock state if and only if the wait-for graph has a cycle
Deadlock Avoidance
o 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.
Distributed database
Database systems that run on each site are independent of each other Transactions may
access data at one or more sites
Distributed database is a system in which storage devices are not connected to a common
processing unit.
Database is controlled by Distributed Database Management System and data may be
stored at the same location or spread over the interconnected network. It is a loosely
coupled system.
Shared nothing architecture is used in distributed databases.
Advantages of Replication
Reliability − In case of failure of any site, the database system continues to work
since a copy is available at another site(s).
Reduction in Network Load − Since local copies of data are available, query
processing can be done with reduced network usage, particularly during prime
hours. Data updating can be done at non-prime hours.
Quicker Response − Availability of local copies of data ensures quick query
processing and consequently quick response time.
Simpler Transactions − Transactions require less number of joins of tables located at
different sites and minimal coordination across the network. Thus, they become
simpler in nature.
Example:
2. Vertical Fragmentation
Fragmentation1:
SELECT * FROM Acc_NO
Fragmentation2:
SELECT * FROM Balance
3) Hybrid Fragmentation or MIXED Fragmentation
Fragmentation1:
SELECT * FROM Emp_Name WHERE Emp_Age < 40
Fragmentation2:
SELECT * FROM Emp_Id WHERE Emp_Address= 'Pune' AND Salary < 14000