0% found this document useful (0 votes)
64 views13 pages

Dbms Question Bank Answers Unit 4

Uploaded by

pavannaidu1424
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
64 views13 pages

Dbms Question Bank Answers Unit 4

Uploaded by

pavannaidu1424
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 13

DBMS QUESTION BANK ANSWERS

SHORT ANSWERS (2 Marks)

1) In SQL, ROLLBACK is a command that causes all data changes since the last BEGIN WORK , or
START TRANSACTION to be discarded by the relational database management systems
(RDBMS), so that the state of the data is "rolled back" to the way it was before those
changes were made.

2) When multiple transactions are running concurrently then there is a possibility that the
database may be left in an inconsistent state. Serializability is a concept that helps us to
check which schedules are serializable. A serializable schedule is the one that always leaves
the database in consistent state.

3) In the shadow-copy scheme, a transaction that wants to update the database first creates a
complete copy of the database. All updates are done on the new database copy, leaving the
original copy, the shadow copy, untouched. If at any point the transaction has to be aborted,
the system merely deletes the new copy.

4) A lock is a data variable which is associated with a data item. This lock signifies that
operations that can be performed on the data item. Locks in DBMS help synchronize access
to the database items by concurrent transactions. All lock requests are made to the
concurrency-control manager.

5) Use the LOCK TABLE statement to lock one or more tables, table partitions, or table
subpartitions in a specified mode. This lock manually overrides automatic locking and
permits or denies access to a table or view by other users for the duration of your operation.

6) Growing phase: In the growing phase, a new lock on the data item may be acquired by the
transaction, but none can be released. Shrinking phase: In the shrinking phase, existing lock
held by the transaction may be released, but no new locks can be acquired.

7) The only difference between 2PL and strict 2PL is that Strict-2PL does not release a lock after
using it. Strict-2PL waits until the whole transaction to commit, and then it releases all the
locks at a time.

8) The Timestamp Ordering Protocol is used to order the transactions based on their
Timestamps. The order of transaction is nothing but the ascending order of the transaction
creation. The priority of the older transaction is higher that's why it executes first.

9) A deadlock exists in the system if and only if there is a cycle in the wait-for graph. In order to
detect the deadlock, the system needs to maintain the wait-for graph and periodically
system invokes an algorithm that searches for the cycle in the wait-for graph.

10) Two-Phase Locking –


 Growing Phase: New locks on data items may be acquired but none can be released.
 Shrinking Phase: Existing locks may be released but no new locks can be acquired.

11) Soft failure is the type of failure that causes the loss in volatile memory of the computer and
not in the persistent storage. A hard failure is the type of failure that causes loss of data in
the persistent or non-volatile storage like disk. Network failures are prevalent in distributed
or network databases.

12) In the context of transaction processing, the acronym ACID refers to the four key properties
of a transaction: atomicity, consistency, isolation, and durability.

13) Transaction States in DBMS


 Active State – When the instructions of the transaction are running then the transaction is in
active state.
 Partially Committed
 Failed State
 Aborted State
 Committed State
 Terminated State

14) Basic Timestamp Ordering –


Every transaction is issued a timestamp based on when it enters the system.
Strict Timestamp Ordering –
A variation of Basic TO is called Strict TO ensures that the schedules are both Strict and
Conflict Serializable.

15) Deadlock can be prevented by eliminating any of the four necessary conditions, which are
mutual exclusion, hold and wait, no preemption, and circular wait. Mutual exclusion, hold
and wait and no preemption cannot be violated practically. Circular wait can be feasibly
eliminated by assigning a priority to each resource.

16) Drawbacks of Shadow processing techinque

 Data is fragmented or scattered.


 Garbage collection problem. Database pages containing old versions of modified data need
to be garbage collected after every transaction.
 Concurrent transactions are difficult to execute.

LONG ANSWERS (8/16 Marks)

1) Concurrency control concept comes under the Transaction in database management system
(DBMS). It is a procedure in DBMS which helps us for the management of two simultaneous
processes to execute without conflicts between each other, these conflicts occur in multi
user systems.
Concurrency can simply be said to be executing multiple transactions at a time. It is required
to increase time efficiency. If many transactions try to access the same data, then
inconsistency arises. Concurrency control required to maintain consistency data.
For example, if we take ATM machines and do not use concurrency, multiple persons cannot
draw money at a time in different places. This is where we need concurrency.
Advantages
The advantages of concurrency control are as follows −
 Waiting time will be decreased.
 Response time will decrease.
 Resource utilization will increase.
 System performance & Efficiency is increased.
Control concurrency
The simultaneous execution of transactions over shared databases can create several data
integrity and consistency problems.
For example, if too many people are logging in the ATM machines, serial updates and
synchronization in the bank servers should happen whenever the transaction is done, if not
it gives wrong information and wrong data in the database.
Why use Concurrency method?
Reasons for using Concurrency control method is DBMS:
 To apply Isolation through mutual exclusion between conflicting transactions
 To resolve read-write and write-write conflict issues
 To preserve database consistency through constantly preserving execution obstructions
 The system needs to control the interaction among the concurrent transactions. This control
is achieved using concurrent-control schemes.
 Concurrency control helps to ensure serializability
Concurrency control techniques
The concurrency control techniques are as follows −
Locking
Lock guaranties exclusive use of data items to a current transaction. It first accesses the data
items by acquiring a lock, after completion of the transaction it releases the lock.
Types of Locks
The types of locks are as follows −
 Shared Lock [Transaction can read only the data item values]
 Exclusive Lock [Used for both read and write data item values]
Time Stamping
Time stamp is a unique identifier created by DBMS that indicates relative starting time of a
transaction. Whatever transaction we are doing it stores the starting time of the transaction
and denotes a specific time.
This can be generated using a system clock or logical counter. This can be started whenever
a transaction is started. Here, the logical counter is incremented after a new timestamp has
been assigned.
Optimistic
It is based on the assumption that conflict is rare and it is more efficient to allow
transactions to proceed without imposing delays to ensure serializability.

3) Deadlock in operating system is a situation of indefinite blocking of one or more processes


that compete for resources.
Deadlock prevention: The possibility of deadlock is excluded before making requests, by
eliminating one of the necessary conditions for deadlock. Example: Only allowing traffic from
one direction, will exclude the possibility of blocking the road.
The conditions for deadlock are:
1. Mutual exclusion
2. Hold and wait
3. No preemption
4. Circular wait.

Deadlock prevention techniques refer to violating any one of the four necessary
conditions. We will see one by one how we can violate each of them to make safe requests
and which is the best approach to prevent deadlock.

Mutual Exclusion

Some resources are inherently unshareable, for example: Printer. For unshareable
resources, processes require exclusive control of the resources.

Mutual exclusion means that unshareable resources cannot be accessed simultaneously


by processes.

Shared resources do not cause deadlock but some resources can't be shared among
processes, leading to a deadlock.

For example: read operation on a file can be done simultaneously by multiple processes,
but write operation cannot. Write operation requires sequential access, so, some
processes have to wait while another process is doing a write operation.

It is not possible to eliminate mutual exclusion, as some resources are inherently non
shareable,

For example: Tape drive, as only one process can access data from a Tape drive at a time.

For other resources like printer, we can use a technique called Spooling.

Spooling: It stands for Simultaneous Peripheral Operations On-line.

A Printer has associated memory which can be used as a spooler directory (memory which
is used to store files that are to be printed next).

In spooling, when multiple processes request for the printer, their jobs ( instructions of the
processes that require printer access) are added to the queue in the spooler directory.

The printer is allocated to jobs on a first come first serve (FCFS) basis. In this way, the
process does not have to wait for the printer and it continues its work after adding
its job in the queue.
We can understand the working of Spooler directory better with the diagram given below:

out

Job1 Job2

in Queue

Spooler Directory
In : Pointer to next file to be printed
Out : Pointer to next empty cell

Challenges of Spooling:
 Spooling can only be used for the resources with associated memory, like a Printer.
 It may also causes race condition. Race condition is the situation where two or more
processes are accessing a resource and the final results cannot be definitively determined.
For example: In printer spooling, if process A overwrites the job of process B in the queue,
then process B will never receive the output.
 It is not a full proof method as after the queue becomes full, incoming processes go in a
waiting state.
For example: If the size of the queue is 10 blocks then whenever there are more than 10
processes, they will go in waiting state.
Hold and Wait
Hold and wait is a condition in which a process is holding one resource while simultaneously
waiting for another resource that is being held by another process. The process cannot
continue till it gets all the required resources.
In the diagram given below:

Resource 3

Process 1

Resource 1
Resource 2

Process 2
 Resource 1 is allocated to Process 2

 Resource 2 is allocated to Process 1

 Resource 3 is allocated to Process 1

 Process 1 is waiting for Resource 1 and holding Resource 2 and Resource 3

 Process 2 is waiting for Resource 2 and holding Resource 1

There are two ways to eliminate hold and wait:-

1. By eliminating wait:

The process specifies the resources it requires in advance so that it does not have to wait for
allocation after execution starts.

For Example: Process1 declares in advance that it requires both Resource1 and Resource2

2. By eliminating hold:

The process has to release all resources it is currently holding before making a new request.

4) Not Done yet

5) Not Done yet

6) Shadow paging is a technique for providing atomicity and durability in


database systems.
• Shadow paging is a copy-on-write technique for avoiding in-place updates of pages.
Instead, when a page is to be modified, a shadow page is allocated.
• Since the shadow page has no references (from other pages on disk), it can be modified
liberally, without concern for consistency constraints, etc. When the page is ready to
become durable, all pages that referred to the original are updated to refer to the new
replacement page instead. Because the page is "activated" only when it is ready, it is
atomic.
• This increases performance significantly by avoiding many writes on hotspots high up in
the referential hierarchy (e.g.: a file system superblock) at the cost of high commit latency.
Shadow paging considers:
1. The database is partitioned into fixed-length blocks referred to as PAGES.
2. Page table has n entries – one for each database page.
3. Each contain pointer to a page on disk (1 to 1st page on database and so on…).
The idea is to maintain 2 pages tables during the life of transaction.
1. The current page table
2. The shadow page table
When transaction starts, both page tables are identical
1. The shadow page table is never changed over the duration of the transaction.
2. The current page table may be changed when a transaction performs a write
operation.
3. All input and output operations use the current page table to locate database
pages on disk.

Advantages:
• No Overhead for writing log records.
• No Undo / No Redo algorithm.
• Recovery is faster.
Disadvantages:
• Data gets fragmented or scattered.
• After every transaction completion database pages containing old version of modified
data need to be garbage collected.
• Hard to extend algorithm to allow transaction to run concurrently.

7) A transaction is a single logical unit of work which accesses and possibly modifies the
contents of a database. Transactions access data using read and write operations. In
order to maintain consistency in a database, before and after the transaction,
certain properties are followed. These are called ACID properties.

A READ ONLY transaction is a transaction in which the read consistency is set at the transaction
level. In a READ ONLY transaction, a logical snapshot of the database is created at the beginning
of the transaction and released at the end of the transaction. This guaranties that all reads in all
statements within this transaction get consistent data from the database.

For example, if you have a transaction with many statements that takes 10 hours to be executed,
a snapshot of the database will be created for this transaction for 10 hours. If a query statement is
executed at the beginning of the transaction and at the end of the transaction, it will return the
same result guarantied. In another word, data changes made during this 10 hours by other users
will not impact the execution of statements within this transaction.

A READ WRITE transaction is a transaction in which the read consistency is set at the statement
level. In a READ WRITE transaction, a logical snapshot of the database is created at the
beginning of the execution of each statement and released at the end of the execution. This
guaranties that all reads within a single statement get consistent data from the database.

For example, if you have a query statement that takes 10 minutes to be executed, a snapshot of
the database will be created for this statement for 10 minutes. If a subquery is used in this
statement, it will get the consistent data no matter when it gets executed within this 10 minutes. In
another word, data changes made during this 10 minutes by other users will not impact the
execution of this query statement.

By default, all transactions are started as READ WRITE transactions.

When you abort a transaction, all database modifications performed under the protection of
the transaction are discarded, and all locks currently held by the transaction are released. In
this event, your data is simply left in the state that it was in before the transaction began
performing data modifications.

Once you have aborted a transaction, the transaction handle that you used for the
transaction is no longer valid. To perform database activities under the control of a new
transaction, you must obtain a fresh transactional handle.

To abort a transaction, call DB_TXN->abort().

8) In the context of transaction processing, the


acronym ACID refers to the four key properties of a
transaction: atomicity, consistency, isolation, and durability.

Atomicity
All changes to data are performed as if they are a single operation.
That is, all the changes are performed, or none of them are.
For example, in an application that transfers funds from one
account to another, the atomicity property ensures that, if a debit
is made successfully from one account, the corresponding credit is
made to the other account.
Consistency
Data is in a consistent state when a transaction starts and when it
ends.
For example, in an application that transfers funds from one
account to another, the consistency property ensures that the total
value of funds in both the accounts is the same at the start and
end of each transaction.
Isolation
The intermediate state of a transaction is invisible to other
transactions. As a result, transactions that run concurrently appear
to be serialized.
For example, in an application that transfers funds from one
account to another, the isolation property ensures that another
transaction sees the transferred funds in one account or the other,
but not in both, nor in neither.
Durability
After a transaction successfully completes, changes to data persist
and are not undone, even in the event of a system failure.
For example, in an application that transfers funds from one
account to another, the durability property ensures that the
changes made to each account will not be reversed.
A transaction goes through many different states throughout its life cycle.
These states are called as transaction states.
Transaction states are as follows-
1. Active state
2. Partially committed state
3. Committed state
4. Failed state
5. Aborted state
6. Terminated state

1. Active State-
 This is the first state in the life cycle of a transaction.
 A transaction is called in an active state as long as its instructions are getting
executed.
 All the changes made by the transaction now are stored in the buffer in main
memory.

2. Partially Committed State-

 After the last instruction of transaction has executed, it enters into a partially
committed state.
 After entering this state, the transaction is considered to be partially committed.
 It is not considered fully committed because all the changes made by the
transaction are still stored in the buffer in main memory.

3. Committed State-

 After all the changes made by the transaction have been successfully stored into
the database, it enters into a committed state.
 Now, the transaction is considered to be fully committed.

4. Failed State-

 When a transaction is getting executed in the active state or partially committed


state and some failure occurs due to which it becomes impossible to continue
the execution, it enters into a failed state.

5. Aborted State-

 After the transaction has failed and entered into a failed state, all the changes
made by it have to be undone.
 To undo the changes made by the transaction, it becomes necessary to roll back
the transaction.
 After the transaction has rolled back completely, it enters into an aborted state.

6. Terminated State-

 This is the last state in the life cycle of a transaction.


 After entering the committed state or aborted state, the transaction finally enters
into a terminated state where its life cycle finally comes to an end.
9) Two-phase locking (2PL)
o The two-phase locking protocol divides the execution phase of the
transaction into three parts.
o In the first part, when the execution of the transaction starts, it seeks
permission for the lock it requires.
o In the second part, the transaction acquires all the locks. The third phase
is started as soon as the transaction releases its first lock.
o In the third phase, the transaction cannot demand any new locks. It only
releases the acquired locks.

There are two phases of 2PL:

Growing phase: In the growing phase, a new lock on the data item may
be acquired by the transaction, but none can be released.

Shrinking phase: In the shrinking phase, existing lock held by the


transaction may be released, but no new locks can be acquired.

In the below example, if lock conversion is allowed then the following


phase can happen:

1. Upgrading of lock (from S(a) to X (a)) is allowed in growing phase.


2. Downgrading of lock (from X(a) to S(a)) must be done in shrinking
phase.

Example:
The following way shows how unlocking and locking work with 2-PL.

Transaction T1:

o Growing phase: from step 1-3


o Shrinking phase: from step 5-7
o Lock point: at 3

Transaction T2:

o Growing phase: from step 2-6


o Shrinking phase: from step 8-9
o Lock point: at 6

4. Strict Two-phase locking (Strict-2PL)


o The first phase of Strict-2PL is similar to 2PL. In the first phase, after
acquiring all the locks, the transaction continues to execute normally.
o The only difference between 2PL and strict 2PL is that Strict-2PL does not
release a lock after using it.
o Strict-2PL waits until the whole transaction to commit, and then it releases
all the locks at a time.
o Strict-2PL protocol does not have shrinking phase of lock release.

It does not have cascading abort as 2PL does.

You might also like