Dbms 4 Notes
Dbms 4 Notes
Dbms 4 Notes
ACID Properties
A transaction is a very small unit of a program and it may
contain several lowlevel tasks. A transaction in a
database system must maintain Atomicity, Consistency,
Isolation, and Durability − commonly known as ACID
properties − in order to ensure accuracy, completeness, and
data integrity.
Atomicity − This property states that a transaction must
be treated as an atomic unit, that is, either all of its
operations are executed or none. There must be no state
in a database where a transaction is left partially
completed. States should be defined either before the
execution of the transaction or after the
execution/abortion/failure of the transaction..
• 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.
• Atomicity involves the following two operations:
• Abort: If a transaction aborts then all the changes made are not
visible.
• Commit: If a transaction commits then all the changes made are
visible.
• Example: Let's assume that following transaction T consisting of T1
and T2. A consists of Rs 600 and B consists of Rs 300. Transfer Rs
100 from account A to account B.
• T1 T2
• Read(A)
•
A:= A-100
•
Write(A)
• Read(B)
•
Y:= Y+100
It shows that the data which is used at the time of execution of a transaction
cannot be used by the second transaction until the first one is completed.
In isolation, if the transaction T1 is being executed and using the data item
X, then that data item can't be accessed by any other transaction T2 until
the transaction T1 ends.
The concurrency control subsystem of the DBMS enforced the isolation
property.
States of Transactions
A transaction in a database can be in one of the following states
−
Active − In this state, the transaction is being executed.
This is the initial state of every transaction.
Partially Committed − When a transaction executes its
final operation, it is said to be in a partially committed
state.
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.
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
−
o Re-start the transaction
o Kill the transaction
Committed − If a transaction executes all its operations
successfully, it is said to be committed. All its effects are
now permanently established on the database system.
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.
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:
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.
Testing of Serializability
Serialization Graph is used to test the Serializability of a schedule.
Assume a schedule S. For S, we construct a graph known as precedence
graph.
This graph has a pair G = (V, E), where V consists a set of vertices, and E
consists a set of edges.
The set of vertices is used to contain all the transactions participating in the
schedule.
The set of edges is used to contain all edges Ti ->Tj for which one of the
three conditions holds:
Create a node Ti → Tj if Ti executes write (Q) before Tj executes read (Q).
Create a node Ti → Tj if Ti executes read (Q) before Tj executes write (Q).
Create a node Ti → Tj if Ti executes write (Q) before Tj executes write (Q).
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.
Explanation:
Read(A): In T1, no subsequent writes to A, so no new edges
If we can convert a non serial schedule to a serial schedule then we can say it
is consistent schedule.
But if we cannot convert a non serial to serial schedule it does not mean it is
inconsistent
It is not guarantee that a student not passing EAMCET is poor ….
If write and write happens and it is called blind write ,because they are not
reading. But this is also conflicting bcos the final value written in database is
different.
2 instructions are said to be conflicting when they belong to different
transactions . But they must operate on same data value and one of the
instruction should be write instruction.
How to convert this non serial to serial schedule
<Tn, Start>
execution, it writes a log about it.
When the transaction modifies an item X, it write logs as
follows −
<Tn, X, V1, V2>
<Tn, commit>
When the transaction finishes, it logs −
The database can be modified using two approaches −
Deferred database modification − All logs are written on
to the stable storage and the database is updated when a
transaction commits.
Immediate database modification − Each log follows an
actual database modification. That is, the database is
modified immediately after every operation.
Multiple Granularity ■
Allow data items to be of various sizes and define a hierarchy of
data granularities, where the small granularities are nested
within larger ones ■ Can be represented graphically as a tree
(but don't confuse with treelocking protocol) ■ When a
transaction locks a node in the tree explicitly, it implicitly locks
all the node's descendents in the same mode. ■ Granularity of
locking (level in tree where locking is done): ● fine
granularity (lower in tree): high
concurrency, high locking overhead ● coarse granularity (higher
in tree): low locking overhead, low concurrency
Levels
are DB
Tables
Records
Fields
ValidationBased Protocol
Types of failures –
There are basically following types of failures that may
occur and leads to failure of the transaction such as:
1. Transaction failure
2. System failure
3. Media failure and so on.
Let us try to understand the different types of failures that may
occur during the transaction.
1. System crash –
A hardware, software or network error occurs comes under
this category this types of failures basically occurs during
the execution of the transaction. Hardware failures are
basically considered as Hardware failure.
2. System error –
Some operation that is performed during the transaction is the
reason for this type of error to occur, such as integer or
divide by zero. This type of failures is also known as the
transaction which may also occur because of erroneous
parameter values or because of a logical programming
error. In
addition to this user may also interrupt the execution
during execution which may lead to failure in the
transaction.
3. Local error –
This basically happens when we are doing the transaction
but certain conditions may occur that may lead to
cancellation of the transaction. This type of error is
basically coming under Local error. The simple example of
this is that data for the transaction may not found. When
we want to debit money from an insufficient balance
account which leads to the cancellation of our request or
transaction. And this exception should be programmed in
the transaction itself so that it wouldn’t be considered as a
failure.
4. Concurrency control enforcement –
The concurrency control method may decide to abort the
transaction, to start again because it basically violates
serializability or we can say that several processes are in a
deadlock.
5. Disk failure –
This type of failure basically occur when some disk
loses their data because of a read or write malfunction or
because of a disk read/write head crash. This may
happen during a read /write operation of the transaction.
6. Castropher –
These are also known as physical problems it basically
refers to the endless list of problems that include power
failure or air-conditioning failure, fire, theft sabotage
overwriting disk or tapes by mistake and mounting of the
wrong tape by the operator.
Protecting data against loss, corruption, disasters (manmade or natural)
and other problems is one of the top priorities for IT organizations. In
concept, the ideas are simple, although implementing an efficient and
effective set of backup operations can be difficult.
The term backup has become synonymous with data protection over the
past several decades and may be accomplished via several methods.
Backup software applications have been developed to reduce the
complexity of performing backup and recovery operations. Backing up
data is only one part of a disaster protection plan, and may not provide
the level of data and disaster recovery capabilities desired without
careful design and testing.
Full
backups
Incremental backups
Differential backups
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. An online backup system is a
mechanism where every bit of the real-time data is backed up
simultaneously at two distant places. One of them is directly connected
to the system and the other one is kept at a remote place as backup.
As soon as the primary database storage fails, the backup system senses
the failure and switches the user system to the remote storage.
Sometimes this is so instant that the users can’t even realize a failure.
DBMS | Log based recovery