Professional Documents
Culture Documents
Checklist and Deadlock
Checklist and Deadlock
same time log files are created and it utilizes system memory space for
storage. The size of the log file may increase continuously and at one point it is
difficult to handle. With the help of a checkpoint mechanism, we can remove all
log files from the system and store them as secondary storage disks permanently.
We can declare a checkpoint before which the DBMS is inconsistent state and all
requires log files for re-execution, but searching log files is a time-consuming
o The checkpoint is a type of mechanism where all the previous logs are
removed from the system and permanently stored in the storage disk.
o When it reaches to the checkpoint, then the transaction will be updated into
the database, and till that point, the entire log file will be removed from the
file. Then the log file is updated with the new step of transaction till next
checkpoint and so on.
o The checkpoint is used to declare a point before which the DBMS was in the
consistent state, and all transactions were committed.
In the following manner, a recovery system recovers the database from this failure:
o The recovery system reads log files from the end to start. It reads log files
from T4 to T1.
o The transaction is put into redo state if the recovery system sees a log with
<Tn, Start> and <Tn, Commit> or just <Tn, Commit>. In the redo-list and
their previous list, all the transactions are removed and then redone before
o For example: In the log file, transaction T2 and T3 will have <Tn, Start>
and <Tn, Commit>. The T1 transaction will have only <Tn, commit> in the
log file. That's why the transaction is committed after the checkpoint is
o The transaction is put into undo state if the recovery system sees a log with
<Tn, Start> but no commit or abort log found. In the undo-list, all the
o For example: Transaction T4 will have <Tn, Start>. So T4 will be put into
undo list since this transaction is not yet complete and failed amid.
Different Types of Checkpoint:
1. Automatic Checkpoint
2. Indirect Checkpoints
3. Internal Checkpoints
4. Manual Checkpoints
1. Automatic Checkpoint
Every time each database without a user-defined recovery time, the SQL server
during the system restart. Automatic checkpoint depends on the number of log files
generated in the database. After a system crash, the recovery time depends on the
amount of time required to redo a dirty page which is more than recovery server
time.
2. Indirect Checkpoints
In indirect checkpoint, recovery time is maintained at SQL server database engine
checkpoint that means a number of dirty pages are less as a compared threshold
value in the database. In indirect checkpoint, dirty pages in the database are written
the default recovery time is 60 sec for the created database. Physically we can
3. Internal Checkpoints
An internal checkpoint is used many times to take a backup of the database. It is
also used to add databases, remove database files, and clean SQL servers.
This is the main use of internal checkpoints in DBMS. When 70% of transaction
log files are created on the server file then the server is shut down.
4. Manual Checkpoints
This is an optional checkpoint provided in DBMS to provide internal time
specified then a manual checkpoint will be run for completion, the required
each transaction is waiting for a data item that is being locked by some other
a directed graph in which the vertices denote transactions and the edges denote
for one another to give up locks. Deadlock is said to be one of the most feared
forever.
For example: In the student table, transaction T1 holds a lock on some rows and
needs to update some rows in the grade table. Simultaneously, transaction T2 holds
locks on some rows in the grade table and needs to update the rows in the Student
lock and similarly, transaction T2 is waiting for T1 to release its lock. All activities
come to a halt state and remain at a standstill. It will remain in a standstill until the
Deadlock prevention.
Deadlock avoidance.
that will lead to deadlocks. The convention is that when more than one
transactions request for locking the same data item, only one of them is granted
the lock.
One of the most popular deadlock prevention methods is pre-acquisition of all the
locks. In this method, a transaction acquires all the locks before starting to execute
and retains the locks for the entire duration of transaction. If another transaction
needs any of the already acquired locks, it has to wait until all the locks it needs
are available. Using this approach, the system is prevented from being deadlocked
are allocated in such a way that deadlock never occurs, then the deadlock
can be prevented.
whether they can create a deadlock situation or not. If they do, then the
analyzes the transactions and the locks to determine whether or not waiting leads
to a deadlock.
The method can be briefly stated as follows. Transactions start executing and
request data items that they need to lock. The lock manager checks whether the
lock is available. If it is available, the lock manager allocates the data item and the
transaction acquires the lock. However, if the item is locked by some other
whether keeping the transaction in waiting state will cause a deadlock or not.
Accordingly, the algorithm decides whether the transaction can wait or one of the
There are two algorithms for this purpose, namely wait-die and wound-wait.
In this scheme:
If a transaction requests for a resource which is already held with a conflicting lock
by another transaction then the DBMS simply checks the timestamp of both
transactions. It allows the older transaction to wait until the resource is available
for execution.
Let's assume there are two transactions Ti and Tj and let TS(T) is a timestamp of
requesting for resources held by T2 then the following actions are performed by
DBMS:
1. Check if TS(Ti) < TS(Tj) - If Ti is the older transaction and Tj has held
some resource, then Ti is allowed to wait until the data-item is available for
2. Check if TS(Ti) < TS(Tj) - If Ti is older transaction and has held some
resource and if Tj is waiting for it, then Tj is killed and restarted later with
if the older transaction requests for a resource which is held by the younger
transaction, then older transaction forces younger one to kill the transaction
and release the resource. After the minute delay, the younger transaction is
Younger transaction, then the younger transaction is asked to wait until older
releases it.
periodically and removes deadlock in case there is one. It does not check for
the transaction is allowed to lock the data item; otherwise the transaction is
allowed to wait.
DBMS should detect whether the transaction is involved in a deadlock or not. The
lock manager maintains a Wait for the graph to detect the deadlock cycle in the
database.