DBMS-Module - 5 Updated
DBMS-Module - 5 Updated
Module -- 5
Transaction Processing, Concurrency Control,
and Recovery
DBMS - Transaction
• What is a Transaction?
A transaction is a set of SQL statements which Oracle
treats as a Single Unit. i.e. all the statements should
execute successfully or none of the statements
should execute.
• To control transactions Oracle does not
make any DML statements permanent
unless you commit it.
COMMIT ;
Example
>commit;
ROLLBACK
Example:
delete from emp;
rollback; /* undo the changes */
SAVEPOINT
Specify a point in a transaction to which later you can roll
back.
Examples:
insert into emp (empno, ename, sal)
values (109,’Sami’,3000);
savepoint a;
Schedules
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.
Cascade less Recoverable Schedule:
• Cascade less recoverable schedules are a type of transaction
schedule in database management systems (DBMS) that
guarantee both cascade lessness and recoverability.
• A cascade less recoverable schedule ensures both of these
properties by using strict two-phase locking, where locks are
acquired on all data items accessed by a transaction before any
updates are made, and the locks are held until the transaction is
either committed or aborted.
Cascade less recoverable schedule :
The below Table 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. But if T1 fails before commit, no
other transaction has read its value, so there is no need to rollback other
transaction. So this is a Cascade less recoverable schedule.
Serializability
Conflict
View Serializability
Serializability
Non-serializable Schedule Types:-
Non-serializable
schedule
Recoverable Non-Recoverable
Schedule Schedule
There exists a cycle in the above graph. Therefore, the schedule S is not conflict
serializable.
Check for Serializability
Serializability
Yes
Conflict Serializability? Serializable
No s
Ye
Transaction T1:
Transaction T2:
Disadvantages:
It does not ensure recoverability as it suffers from
Cascading Rollback.
It may suffer from deadlock.
Cascading Rollbacks in 2-PL –
Here,
In the above situation T1 waits for B and T2 waits for A. The waiting time never
ends. Both the transaction cannot proceed further at least any one releases the lock
voluntarily. This situation is called deadlock.
Volatile storage like RAM stores all the active logs, disk buffers,
and related data.
We can have checkpoints at multiple stages so as to save
the contents of the database periodically.
<dump> can be marked on a log file, whenever the
database contents are dumped from a non-volatile memory
to a stable one.
Recovery
When the system recovers from a failure, it
•
as checkpoints.
Remote backup: Here a backup copy of the database is
stored at a remote location from where it can be restored
in case of a catastrophe.
Alternatively, database backups can be taken on
magnetic tapes and stored at a safer place. This backup
can later be transferred onto a freshly installed database
to bring it to the point of backup.
Remote Backup
Remote backup provides a sense of security in case the
primary location where the database is located gets
destroyed.
Remote backup can be offline or real-time or online. In case
it is offline, it is maintained manually.
• Online backup systems are more real-time and lifesavers
for database administrators and investors.
As time passes, the log file may grow too big to be handled
at all.
Shadow paging is one of the techniques that is used to recover from failure. We all know that
recovery means getting back the information, which is lost. It helps to maintain database
consistency in case of failure.
Step 1 − Page is a segment of memory. Page table is an index of pages. Each table entry
points to a page on the disk.
Step 2 − Two page tables are used during the life of a transaction: the current page table and
the shadow page table. Shadow page table is a copy of the current page table.
Step 3 − When a transaction starts, both the tables look identical, the current table is updated
for each write operation.
Step 4 − The shadow page is never changed during the life of the transaction.
Step 5 − When the current transaction is committed, the shadow page entry becomes a copy of
the current page table entry and the disk block with the old data is released.
Step 6 − The shadow page table is stored in non-volatile memory. If the system crash occurs,
then the shadow page table is copied to the current page table.
To understand concept, consider above figure. In this 2 write operations are
performed on page 3 and 5. Before start of write operation on page 3, current page
table points to old page 3. When write operation starts following steps are
performed :
Disadvantages