DBMS Unit-4
DBMS Unit-4
In simple words, it can be said that a rollback operation does undo the
operations of transactions that were performed before its interruption to
achieve a safe state of the database and avoid any kind of ambiguity or
inconsistency.
Transaction Schedules
When multiple transaction requests are made at the same time, we need to decide
their order of execution. Thus, a transaction schedule can be defined as a
chronological order of execution of multiple transactions. There are broadly two
types of transaction schedules discussed as follows:
i) Serial Schedule
In this kind of schedule, when multiple transactions are to be executed, they
are executed serially, i.e. at one time only one transaction is executed while
others wait for the execution of the current transaction to be completed. This
ensures consistency in the database as transactions do not execute
simultaneously.
But, it increases the waiting time of the transactions in the queue, which in
turn lowers the throughput of the system, i.e. number of transactions executed
per time.
To improve the throughput of the system, another kind of schedule are used
which has some more strict rules which help the database to remain consistent
even when transactions execute simultaneously.
ii) Non-Serial Schedule
To reduce the waiting time of transactions in the waiting queue and improve
the system efficiency, we use nonserial schedules which allow multiple
transactions to start before a transaction is completely executed. This may
sometimes result in inconsistency and errors in database operation.
So, these errors are handled with specific algorithms to maintain the
consistency of the database and improve CPU throughput as well.
Non-serial schedules are also sometimes referred to as parallel schedules, as
transactions execute in parallel in these kinds of schedules.
Serializable
Serializability in DBMS is the property of a nonserial schedule that
determines whether it would maintain the database consistency or not.
The nonserial schedule which ensures that the database would be consistent
after the transactions are executed in the order determined by that schedule is
said to be Serializable Schedules.
The serial schedules always maintain database consistency as a transaction
starts only when the execution of the other transaction has been completed
under it.
Thus, serial schedules are always serializable.
A transaction is a series of operations, so various states occur in its
completion journey. They are discussed as follows:
i) Active
It is the first stage of any transaction when it has begun to execute. The
execution of the transaction takes place in this state.
Page 2 of 20
Unit IV
Page 3 of 20
Unit IV
Page 4 of 20
Unit IV
Schedule
A series of operation from one transaction to another transaction is known as
schedule. It is used to preserve the order of the operation in each of the individual
transaction.
Page 5 of 20
Unit IV
1. Serial Schedule
The serial schedule is a type of schedule where one transaction is executed
completely before starting another transaction. In the serial schedule, when the first
transaction completes its cycle, then the next transaction is executed.
For example: Suppose there are two transactions T1 and T2 which have some
operations. If it has no interleaving of operations, then there are the following two
possible outcomes:
1. Execute all the operations of T1 which was followed by all the operations of
T2.
2. Execute all the operations of T1 which was followed by all the operations of
T2.
In the given (a) figure, Schedule A shows the serial schedule where T1
followed by T2.
In the given (b) figure, Schedule B shows the serial schedule where T2
followed by T1.
2. Non-serial Schedule
If interleaving of operations is allowed, then there will be non-serial schedule.
It contains many possible orders in which the system can execute the
individual operations of the transactions.
In the given figure (c) and (d), Schedule C and Schedule D are the non-serial
schedules. It has interleaving of operations.
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.
Page 6 of 20
Unit IV
Page 7 of 20
Unit IV
Her
e, Schedule A and Schedule B are serial
schedule. Schedule C and Schedule D are
Non-serial schedule.
Page 8 of 20
Unit IV
Serializability in DBMS
If a non-serial schedule can be transformed into its corresponding serial schedule, it
is said to be serializable. Simply said, a non-serial schedule is referred to as a
serializable schedule if it yields the same results as a serial timetable.
Types of Serializability
There are two ways to check whether any non-serial schedule is serializable.
1. Conflict serializability
Conflict serializability refers to a subset of serializability that focuses on
maintaining the consistency of a database while ensuring that identical data items
are executed in an order. In a
DBMS each transaction has a value and all the transactions, in the database rely on
this uniqueness. This uniqueness ensures that no two operations with the conflict
value can occur simultaneously.
For example lets consider an order table and a customer table as two instances. Each
order is associated with one customer even though a single client may place orders.
However there are restrictions for achieving conflict serializability in the database.
Here are a few of them.
1. Different transactions should be used for the two procedures.
2. The identical data item should be present in both transactions.
3. Between the two operations, there should be at least one write operation.
Example
Three transactions—t1, t2, and t3—are active on a schedule “S” at once. Let’s
create a graph of precedence.
Transaction – 1 (t1) Transaction – 2 (t2) Transaction – 3 (t3)
R(a)
R(b)
R(b)
W(b
W(a) )
W(a)
R(a)
W(a
)
Page 9 of 20
Unit IV
Following command will delete the record from the database, but if we immediately
performs ROLLBACK, then this deletion is undone.
Page 11 of 20
Unit IV
For instance -
DELETE FROM Student
WHERE RollNo = 2;
ROLLBACK;
Then the resultant table will be
(3) SAVEPOINT: A SAVEPOINT is a point in a transaction when you can roll the
transaction back to a certain point without rolling back the entire transaction. The
SAVEPOINT can be created as
SAVEPOINT savepoint_name;
Then we can ROLLBACK to SAVEPOIT as
ROLLBACK TO savepoint_name;
For example - Consider Student table as follows –
SQL> SAVEPOINT S3
SQL>DELETE FROM Student
Where RollNo=4
SQL> SAVEPOINT S4
SQL>DELETE FROM Student
Where RollNo=5
SQL> ROLLBACK TO S3;
Then the resultant table will be
Thus the effect of deleting the record having RollNo 2, and RollNo3 is undone.
Recoverability in DBMS
Recoverability is a property of database systems that ensures that, in the event of a
failure or error, the system can recover the database to a consistent state.
Recoverability guarantees that all committed transactions are durable and that their
effects are permanently stored in the database, while the effects of uncommitted
transactions are undone to maintain data consistency.
The recoverability property is enforced through the use of transaction logs, which
record all changes made to the database during transaction processing. When a
failure occurs, the system uses the log to recover the database to a consistent state,
which involves either undoing the effects of uncommitted transactions or redoing
the effects of committed transactions.
goal of recovery techniques is to ensure data integrity and consistency and prevent
data loss.
Followings are types of recovery techniques used in DBMS
Rollback/Undo Recovery Technique
Commit/Redo Recovery Technique
CheckPoint Recovery Technique
Database recovery techniques ensure data integrity in case of system failures.
Rollback/Undo Recovery Technique
The rollback/undo recovery technique is based on the principle of backing out or
undoing the effects of a transaction that has not been completed successfully due to
a system failure or error. This technique is accomplished by undoing the changes
made by the transaction using the log records stored in the transaction log. The
transaction log contains a record of all the transactions that have been performed on
the database. The system uses the log records to undo the changes made by the
failed transaction and restore the database to its previous state.
Commit/Redo Recovery Technique
The commit/redo recovery technique is based on the principle of reapplying the
changes made by a transaction that has been completed successfully to the database.
This technique is accomplished by using the log records stored in the transaction log
to redo the changes made by the transaction that was in progress at the time of the
failure or error. The system uses the log records to reapply the changes made by the
transaction and restore the database to its most recent consistent state.
Checkpoint Recovery Technique
Checkpoint Recovery is a technique used to improve data integrity and system
stability, especially in databases and distributed systems. It entails preserving the
system’s state at regular intervals, known as checkpoints, at which all ongoing
transactions are either completed or not initiated. This saved state, which includes
memory and CPU registers, is kept in stable, non-volatile storage so that it can
withstand system crashes. In the event of a breakdown, the system can be restored to
the most recent checkpoint, which reduces data loss and downtime. The frequency
of checkpoint formation is carefully regulated to decrease system overhead while
ensuring that recent data may be restored quickly.
Overall, recovery techniques are essential to ensure data consistency and availability
in Database Management System, and each technique has its own advantages and
limitations that must be considered in the design of a recovery system.
Shadow Paging:
1. Page Table: The page table maintains the mapping between the logical
addresses used by the transaction and the physical addresses of the shadow
pages. It provides a layer of indirection to access the appropriate data in the
shadow copy.
Page 14 of 20
Unit IV
2. Shadow Pages: Shadow pages are a duplicate set of the original database
pages. They are created during transaction execution to store the modified data
without affecting the original pages. The shadow pages are organized in a
separate area of the memory or storage, allowing for atomic updates during the
transaction.
3. Transaction Log: The transaction log records all the modifications made during
a transaction, including both the original and shadow pages. It captures the
before and after images of each modified page, enabling recovery in case of a
system failure or crash.
Conclusion:
Page 15 of 20
Unit IV
Shadow paging is a powerful technique in DBMS that ensures data consistency and
provides reliable recovery mechanisms. By creating a shadow copy of the database
and applying modifications to it, shadow paging minimizes the risk of data corruption.
It guarantees a consistent view of the database during transaction execution and
simplifies recovery in case of failures. With its benefits of efficiency, minimal
overhead, and scalability, shadow paging continues.
Page 16 of 20
Unit IV
mechanism for recovering from failures and ensuring the consistency of the
database.
Advantages of Log based Recovery
Durability: In the event of a breakdown, the log file offers a dependable and
long-lasting method of recovering data. It guarantees that in the event of a
system crash, no committed transaction is lost.
Faster Recovery: Since log-based recovery recovers databases by replaying
committed transactions from the log file, it is typically faster than alternative
recovery methods.
Incremental Backup: Backups can be made in increments using log-based
recovery. Just the changes made since the last backup are kept in the log file,
rather than creating a complete backup of the database each time.
Lowers the Risk of Data Corruption: By making sure that all transactions
are correctly committed or canceled before they are written to the database ,
log-based recovery lowers the risk of data corruption.
Disadvantages of Log based Recovery
Additional overhead: Maintaining the log file incurs an additional
overhead on the database system, which can reduce the performance of the
system.
Complexity: Log-based recovery is a complex process that requires careful
management and administration. If not managed properly, it can lead to data
inconsistencies or loss.
Storage space: The log file can consume a significant amount of storage
space, especially in a database with a large number of transactions.
Time-Consuming: The process of replaying the transactions from the log file
can be time- consuming, especially if there are a large number of transactions
to recover.
Page 19 of 20
Unit IV
Page 20 of 20