Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

DBMS Unit-4

Download as pdf or txt
Download as pdf or txt
You are on page 1of 19

UNIT-4

WHAT IS TRANSACTION?
• Transactions are a set of operations that are used to perform some logical set of work.
• A transaction is made to change data in a database which can be done by inserting new data,
updating the existing data, or by deleting the data that is no longer required.
• There are certain types of transaction states which tell the user about the current condition of
that database transaction and what further steps to be followed for the processing.
• A transaction can be defined as a group of tasks. A single task is the minimum processing unit
which cannot be divided further.
• A transaction is an action or series of actions that are being performed by a single user or
application program, which reads or updates the contents of the database.
• A transaction can be defined as a logical unit of work on the database. This may be an entire
program, a piece of a program, or a single command (like the SQL commands such as INSERT or
UPDATE), and it may engage in any number of operations on the database. In the database
context, the execution of an application program can be thought of as one or more transactions
with non-database processing taking place in between.
EXAMPLE OF A TRANSACTION
• Let’s take an example of a simple transaction. Suppose a bank employee transfers Rs 500
from A's account to B's account. This very simple and small transaction involves several
low-level tasks.
OPERATIONS OF TRANSACTION

• Following are the main operations of transaction:


• Read(X): Read operation is used to read the value of X from the database and stores it
in a buffer in main memory.
• Write(X): Write operation is used to write the value back to the database from the
buffer.
• Commit: It is used to save the work done permanently.
• Rollback: It is used to undo the work done.
TRANSACTION STATES
Following are the different types of transaction States :
Active State:
 When the operations of a transaction are running then the transaction is said to be
active state.
 If all the read and write operations are performed without any error then it progresses
to the partially committed state, if somehow any operation fails, then it goes to a state
known as failed state.
Partially Committed:
 After all the read and write operations are completed, the changes which were
previously made in the main memory are now made permanent in the database,
after which the state will progress to committed state but in case of a failure it will go
to the failed state.
Failed State:
 If any operation during the transaction fails due to some software or hardware issues,
then it goes to the failed state . The occurrence of a failure during a transaction makes
a permanent change to data in the database. The changes made into the local memory
data are rolled back to the previous consistent state.
Aborted State:
 If the transaction fails during its execution, it goes from failed state to aborted state and because
in the previous states all the changes were only made in the main memory, these uncommitted
changes are either deleted or rolled back.
 The transaction at this point can restart and start afresh from the active state.

Committed State:
 If the transaction completes all sets of operations successfully, all the changes made during the
partially committed state are permanently stored and the transaction is stated to be completed,
thus the transaction can progress to finally get terminated in the terminated state.

Terminated State:
 If the transaction gets aborted after roll-back or the transaction comes from the committed
state, then the database comes to a consistent state and is ready for further new transactions
since the previous transaction is now terminated.
PROPERTIES OF TRANSACTION (ACID PROPERTIES)

• The transaction refers to a small unit of any given program that consists of various low-
level tasks. Every transaction in DBMS must maintain ACID – A (Atomicity), C
(Consistency), I (Isolation), D (Durability). One must maintain ACID so as to ensure
completeness, accuracy, and integrity of data.
• These are used to maintain state consistency in the database, both before and after the
transaction. These are called ACID properties.
Atomicity:
This property means that either the transaction takes place completely at once or doesn’t
happen at all. There is no middle option, i.e., transactions do not occur partially. Each
transaction is considered as one single step which either runs completely or is not executed
at all.
Consistency:
This property means that the integrity constraints of a database are maintained so that the
database is consistent before and after the transaction. It refers to the correctness of a
database.
No transaction should have any adverse effect on the data residing in the database.
If the database was in a consistent state before the execution of a transaction, it must
remain consistent after the execution of the transaction as well.
Isolation:
This property means that multiple transactions can occur concurrently without causing any
inconsistency to the database state.
These transactions occur independently without any external interference.
Changes that occur in a particular transaction are not visible/ accessible to any other
transaction until that particular change in that transaction has been committed.
In other words,
In a database system where more than one transaction are being executed simultaneously
and in parallel, the property of isolation states that all the transactions will be carried out
and executed as if it is the only transaction in the system. No transaction will affect the
existence of any other transaction.
Durability:
This property ensures that once the transaction has completed execution, the updates and
modifications to the database are stored in and written to disk and they remain intact
even if a system failure occurs. These updates become permanent and are stored in the
non-volatile memory.
In other words,
The database should be durable enough to hold all its latest updates even if the system
fails or restarts. If a transaction updates a chunk of data in a database and commits, then
the database will hold the modified data. If a transaction commits but the system fails
before the data could be written on to the disk, then that data will be updated once the
system springs back into action.
DATABASE BACKUP AND RECOVERY
• DATABASE BACKUP
• Database backup basically means that a duplicate of the database information and data is
created and stored in backup server just to be on the safe side. Transaction logs are also
stored in the backup along with the database data because without them, the data would be
useless.

• DATABASE RECOVERY
• Recovery is the process of restoring a database to the correct state in the event of a failure.
• It ensures that the database is reliable and remains in consistent state in case of a failure.

Database recovery can be classified into two parts;


1. Rolling Forward applies redo records to the corresponding data blocks.
2. Rolling Back applies rollback segments to the datafiles. It is stored in transaction tables.
Reasons of Failure in a Database
There can be multiple reasons of failure in a database because of which a
database backup and recovery plan is required. Some of these reasons are:
•User Error - Normally, user error is the biggest reason of data destruction or
corruption in a database. To rectify the error, the database needs to be restored to
the point in time before the error occured.
•Hardware Failure - This can also lead to loss of data in a database. The
database is stored on multiple hard drives across various locations. These hard
drives may sometimes malfunction leading to database corruption. So, it is
important to periodically change them.
•Catastrophic Event - A catastrophic event can be a natural calamity like a flood
or earthquake or deliberate sabotage such as hacking of the database. Either way,
the database data may be corrupted and backup may be required.
• Some of the backup techniques are as follows :
• Full database backup – In this full database including data and database, Meta
information needed to restore the whole database, including full-text catalogs are
backed up in a predefined time series.
• Differential backup – It stores only the data changes that have occurred since the last
full database backup. When some data has changed many times since last full database
backup, a differential backup stores the most recent version of the changed data. For
this first, we need to restore a full database backup.
• Transaction log backup – In this, all events that have occurred in the database, like a
record of every single statement executed is backed up. It is the backup of transaction
log entries and contains all transactions that had happened to the database. Through
this, the database can be recovered to a specific point in time. It is even possible to
perform a backup from a transaction log if the data files are destroyed and not even a
single committed transaction is lost.
• There are two methods that are primarily used for database recovery. These are:
• Log based recovery - In log based recovery, logs of all database transactions are stored
in a secure area so that in case of a system failure, the database can recover the data. All
log information, such as the time of the transaction, its data etc. should be stored before
the transaction is executed.
• Shadow paging - In shadow paging, after the transaction is completed its data is
automatically stored for safekeeping. So, if the system crashes in the middle of a
transaction, changes made by it will not be reflected in the database.
AUTHENTICATION & AUTHORIZATION

• Authentication
• User authentication is to make sure that the person accessing the database is
who he claims to be. Authentication can be done at the operating system level
or even the database level itself. Many authentication systems such as retina
scanners or bio-metrics are used to make sure unauthorized people cannot
access the database.
• Authorization
• Authorization is a privilege provided by the Database Administer. Users of the
database can only view the contents they are authorized to view. The rest of
the database is out of bounds to them.
• The different permissions for authorizations available are:
• Primary Permission - This is granted to users publicly and directly.
• Secondary Permission - This is granted to groups and automatically awarded
to a user if he is a member of the group.
• Public Permission - This is publicly granted to all the users.
• Context sensitive permission - This is related to sensitive content and only
granted to a select users.
• The categories of authorization that can be given to users are:
• System Administrator - This is the highest administrative authorization for a user.
Users with this authorization can also execute some database administrator commands
such as restore or upgrade a database.
• System Control - This is the highest control authorization for a user. This allows
maintenance operations on the database but not direct access to data.
• System Maintenance - This is the lower level of system control authority. It also allows
users to maintain the database but within a database manager instance.
• System Monitor - Using this authority, the user can monitor the database and take
snapshots of it.

You might also like