You are on page 1of 41

.

DATABASE MANAGEMENT
SYSTEMS (DBMS II)
CHAPTER 01
TRANSACTION MANAGEMENT
&
CONCURRENCY CONTROL
DATABASE MANAGEMENT SYSTEMS (DBMS II)

✓ 1.1. Review To DBMS.


✓ 1.2. Transactions in DBMS.
✓ 1.3. Transaction Support in DBMS.
✓ 1.4. Concurrency control.
A. Problems of Concurrent Sharing.
B. Concept of Serializability.
C. Concurrency control mechanism.

✓ 1.5. DATABASE Recovery.


A. Transactions & recovery.
B. Recovery techniques & facilities.
DATABASE MANAGEMENT SYSTEMS (DBMS II)
 As one of the oldest components associated with computers as an
application language is the Database Management System or
(DBMS).
► DBMS: is a computer software program that is designed as the means of
managing all databases that are currently installed on a system hard drive
or network.

► Different types of database management systems exist, with some of


them designed for proper control of databases that are configured for
specific purposes.

► The DBMS is marketed in many forms. Some of the more popular examples of DBMS
solutions are:
1. MICROSOFT ACCESS.
2. SQL SERVER.
3. ORACLE.
4. OTHER DATABASES.
DATABASE MANAGEMENT SYSTEMS (DBMS II)

►What is Standard query language SQL?


►To work with the data in the databases, a database developer
will write programming statements called queries.
Database management systems are accessed, DELETED,
SEARCHED, updated, ......etc using Structured Query
Language (SQL).
►Different brands of database management systems may
require the use of different versions of SQL, though they
have many similarities.
DATABASE MANAGEMENT SYSTEMS (DBMS II)
INTRODUCTIONS TO DBMS TRANSACTIONS

►Many enterprises use databases to store information about


their state. For example: Balances of all depositors at a
bank.
►When an event occurs in the real world that changes the
state of the enterprise, a program is executed to change the
database state in a corresponding way. For example: Bank
balance must be updated when deposit is made.

►Such operations is called a transactions


DATABASE MANAGEMENT SYSTEMS (DBMS II)
►What Does a Transaction Do?

❖ Return information from the database. For example:


Show Balance transaction: Read customer’s balance in database and
output it
❖ Update the database to reflect the occurrence of a real world event.
For example: Deposit transaction: Update customer’s balance in
database
❖ Cause the MAINPULATION of a real world event. For example:
Withdraw transaction: Dispense cash (and update customer’s balance in
database)
DATABASE MANAGEMENT SYSTEMS (DBMS II)
►IN Transaction:
The execution of each transaction must maintain the relationship between
the database state and the enterprise state.

►Therefore additional requirements are placed on the execution of


transactions called ACID PROPERITIES:
1. Atomicity.
2. Consistency.
3. Isolation.
4. Durability.
DATABASE MANAGEMENT SYSTEMS (DBMS II)
► What is TRANSACTION in DBMS?
Definition: A Transaction is a set of commands that perform a given action and
takes the database from a consistent state to another consistent state
depending on the command used.

►Transaction is nothing but applying a QUERY on database to perform a


meaningful or useful operations to retrieve valid information from the
database.
Definition: A transaction is a sequence of one or more SQL commands that
performs a task.
Transaction Processing ensures that when the DBMS is making changes
related to a single task, either all changes are made as a unit together (all at one
time) or no changes are made totally.
Definition: Transaction is an action, or series of action, carried out by a user
command or the Database command, which reads, update, searches, deletes
the content of database.
Definition: In the context of databases, a single logical operation on the data is
called a transaction.
DATABASE MANAGEMENT SYSTEMS (DBMS II)
►A DBMS Transaction Definition:
Transaction in SQL (structured query language) is a larger unit of
database processing that contains one or more database access
operations like insertion, deletion, retrieval and modification
operations.

►A Transaction Characteristics:
►Definition of ACID: In computer science, ACID (atomicity,
consistency, isolation, durability) is a set of properties that guarantee
database transactions are processed reliably.
DATABASE MANAGEMENT SYSTEMS (DBMS II)
► These transactions are required to fulfil certain characteristics and
they are:

Atomicity: The transaction is either performed entirely or not performed at


all.
Isolation: The transaction should not be interfered by any other
transaction executing concurrently. Transactions must be executed independently from
other Transactions. Part of a transaction in progress should not be able to be seen by another
transaction.
Durability: The changes made by the transaction should be permanently
committed in the database. A successfully completed transaction is recorded permanently
in the database and must not be lost due to failures.
Consistency preservation: If the database was consistent before the execution of
the transaction .It should remain consistent after the complete execution of that transaction.
A transaction must alter the database from one constant state to another
constant state.
DATABASE MANAGEMENT SYSTEMS (DBMS II)
►SQL TRANSACTIONS:
SQL Server writes the changes of a transaction to a log file
first.
✓ If the transaction is successful the changes are
COMMITTED and tables are updated or changes are made.
✓ If for some reason the transaction is unsuccessful the
transaction undergoes a ROLLBACK and the previous data
is restored (before the changes took place).

✓ ►There are two types of transactions in SQL


server:

1) Implicit transactions
2) Explicit transactions.
DATABASE MANAGEMENT SYSTEMS (DBMS II)
1) Implicit transactions:
❖ Definition:
Implicit part of the Transaction are those that need to be
specified as a command like all INSERT, DELETE, UPDATE,
CREATE, DROP & OTHER KEY statements they run as
implicit transactions.
For example: if an update query is runed, and a primary key
constraint is violated, a rollback will occur and changes will not
occur.
DATABASE MANAGEMENT SYSTEMS (DBMS II)
►The status of the Implicit Transaction can be either :
A. Commit.
B. Roll-back.

A- Commit transaction:
 Commit transaction signals (shows) that the transaction was
successfully executed and the changes/ updates (if any) made
by the transaction have been committed to the database and
these changes cannot be undone.
B- Roll-back transaction:
 Roll-back signals (shows) that the transaction was not
successfully executed, and the changes/updates made by the
transaction have to be undone.
DATABASE MANAGEMENT SYSTEMS (DBMS II)
EXPLICIT TRANSACTIONS:
Definition: These are the statements written by the programmer. In order
to execute a group of statements to be enforced on the data inside
databases or tables in order to obtain changes. as a transaction we
write the statements within a BEGIN TRANSACTION and COMMIT
TRANSACTION block.
► If an error occurs we can use ROLLBACK, so that previous data state is
restored.
 Implicit transactions are those that mark beginning and end of the
transaction, each statement like update, delete, insert run within these
implicit transactions or the statements written by the user to be enforced on
the data inside databases or tables.
 However, you can explicitly specify the beginning and ending of the
transaction by "begin transaction" and "end transaction" statements
respectively. All the statements within these two boundaries will be
marked as one transaction.
DATABASE MANAGEMENT SYSTEMS (DBMS II)

►Why Transactions are important, why we need


Transactions?
 Transactions are required & needed in DBMS applications
that SAVE & MANIPULATE data & it’s important because it
ensure data integrity.
►Data integrity is enforced when no two people are able to
update/change a record at the same time. Also, modified data
cannot be changed by anyone until it is saved (committed) to
database.
DATABASE MANAGEMENT SYSTEMS (DBMS II)
► Transaction States:
They are as follows:

►Active: the transaction is called active transaction as long as the transaction


is running or executing.
► Partially committed: after the final statement or line of the transaction
commands has been executed then the transaction is partially committed.
► Committed: if the transaction is saved & completed successfully then the
transaction is committed.
► Aborted: if an error occurs then the transaction is rolled back & then
database is restored to its prior state of the transaction then its called aborted
or stoped. Here the user can do two options:
A. Restart the transaction.
B. Kill or stop the transaction.
► Failed: the transaction can no longer proceed & it’s not working.
DATABASE MANAGEMENT SYSTEMS (DBMS II)
► Transaction States:
DATABASE MANAGEMENT SYSTEMS (DBMS II)
DATABASE MANAGEMENT SYSTEMS (DBMS II)
►Data Concurrency and Consistency in a Multiuser
Environment:
► In a single-user database: the user can modify data in the database
without concern for other users modifying the same data at the same time.
► However, in a multiuser database: databases where users
modifying the data at the same time with the same table or with the same
database or both.
❖ the statements of multiple simultaneous transactions can update & modify the
same data.
❖ Transactions executing at the same time need to produce meaningful and
consistent results. Therefore, control of data concurrency and data
consistency is vital in a multiuser database.
Definitions: Data concurrency means that many users can access
data at the same time.
Definitions: Data consistency: means that each user sees a
consistent (valid unit of data) view of the data, including visible changes
made by the user's own transactions and transactions of other users.
DATABASE MANAGEMENT SYSTEMS (DBMS II)

►Definition 1 of Concurrency control: Database concurrency controls


ensure that transactions occur in an ordered fashion. The main job of
these concurrency controls is to protect transactions issued by
different users/applications from affecting each other.
►The concurrency must preserve the four characteristics of database
transactions: atomicity, isolation, consistency and durability.
► Definition 2 of Concurrency control: is a (DBMS) concept that is used
to address conflicts with the simultaneous accessing or altering of data
that can occur with a multi-user system.
Q- Why Concurrency control is important?
► Concurrency control is applied to a DBMS because: is used to coordinate
simultaneous transactions while preserving data integrity. The Concurrency is
about to control the multiple user access of Database.
►How we can a chive data Concurrency control ? Or what is serializability?
To describe consistent transaction behaviour when transactions run at
the same time, database researchers have defined a transaction
isolation model called serializability.
DATABASE MANAGEMENT SYSTEMS (DBMS II)
The SERIALIZABILITY ensures
 Definition 2 of serializability:
that transactions run in such a way that it executes one
transaction at a time by DBMS, or serially, rather than
concurrently (same time).
DATABASE MANAGEMENT SYSTEMS (DBMS II)
 Definition 1 of locking: When many people may be reading the same
data item at the same time, it is usually necessary to ensure that only
one application at a time can change a data item. Locking is a way to do
this. Because of locking, all changes to a particular data item will be
made in the correct order in a transaction.
Definition 2 of locking: Locks are mechanisms that prevent destructive
interaction between transactions accessing the same resource.
DATABASE MANAGEMENT SYSTEMS (DBMS II)
►What are the types of Locking in DBMS?
1. Pessimistic Locking.
2. Optimistic Locking.
► What is pessimistic locking?
❖ Pessimistic Locking:
 This concurrency control strategy involves keeping an entity in a database
locked the entire time it exists in the database's memory. This limits or prevents
users from altering the data entity that is locked.
There are two types of locks that fall under the category of pessimistic
locking:
1. Write lock.
2. Read lock.
DATABASE MANAGEMENT SYSTEMS (DBMS II)
►What is Optimistic locking?
 Optimistic Locking:
This strategy can be used when instances of simultaneous transactions, or
collisions, are expected to be infrequent & very high in chance.
►What is the difference between optimistic & pessimistic
locking?
In contrast with pessimistic locking, optimistic locking doesn't try to prevent the
collisions from occurring. Instead, it aims to detect these collisions and
resolve them on the chance occasions when they occur.
 Pessimistic locking provides a guarantee that database changes are made
safely.
DATABASE MANAGEMENT SYSTEMS (DBMS II)
► Lock Problems:
Deadlock: is one of these problems.
When dealing with locks problems can arise, the first of which being
deadlock.
►What is the dead lock in DBMS?
Deadlock refers to a particular situation where two or more processes are
each waiting for another to release a resource, or more than two
processes are waiting for resources in a circular chain.
 Deadlock is a common problem in multiprocessing where many
processes share a specific type of mutually exclusive resource.
❖ Very important:
 Some computers, usually those intended for the time-sharing
and/or real-time markets, are often equipped with a hardware
lock, or hard lock, which guarantees exclusive access to
processes, forcing serialization. Deadlocks are particularly
disconcerting because there is no general solution to avoid
them.
DATABASE MANAGEMENT SYSTEMS (DBMS II)
DATA BASE RECOVERY
❖ Abstract or introductions:
Backup and recovery are more important today than ever before. Take, for
example, a some major companies usually announce that they are now have
the ability to process nearly half a million transactions per day.
❖ What is significant about that kind of increase? It clearly shows that
businesses today are demanding higher throughput as they continue to store
and process more data. It wasn't long ago that people were measuring data
volumes in terms of gigabytes. Today, however, it is commonplace to manage
a full terabyte of data on a single server --that's roughly equivalent to the data
contained in ten thousand 300-page novels.
These huge volumes demonstrate our extreme reliance on data in today's
business environment. But even as our reliance increases and volumes
swell, so grows the importance of each individual piece of data making up
those volumes. Few organizations can succeed without the assurance
that each of their orders, payments, requests and inquiries are being
properly fulfilled and processed.
DATABASE MANAGEMENT SYSTEMS (DBMS II)
❖ Backup and Recovery:
backup refers to the various strategies and procedures involved in protecting
our database against data loss.
 Backup is the process where we create a copies of an existing data in order
to use them when a vital error occurs or system crash happens so the
organization activities can continue if that data is lost.
❖ The reconstructing of data is achieved through media recovery which refers
to the various operations involved in restoring, rolling forward, and rolling
back backup database files.
❖ Backups Basic Concepts
A backup is a copy of data. This copy can include important parts of the
database such as the control file and data files. A backup is a safeguard
against unexpected data loss and application errors. If you lose the original
data, then you can reconstruct it by using a backup.
Backups are divided into :
1. PHYSICAL BACKUPS .
2. LOGICAL BACKUPS.
DATABASE MANAGEMENT SYSTEMS (DBMS II)
1. PHYSICAL BACKUPS:
 It’s a primary concern in a backup and recovery strategy, they are
copies of physical database files stored on a storage devices such as
cluster server or hard drivers ...etc. We can make physical backups with
either the Recovery Manager (RMAN) utility or operating system
utilities.
Physical backups are database files stored physically on storage
devices: data files and control files.
Physical backups are divided into two categories:
1. IMAGE COPIES
2. STANDARD BACKUP FORMAT.
►IMAGE COPIES: An image copy is an exact duplicate of a data
file. one can create image copies of physical files with
operating system utilities or the RMAN COPY command, and
you can restore them by performing additional processing by
using the RMAN RESTORE command.
DATABASE MANAGEMENT SYSTEMS (DBMS II)
STANDARD BACKUP FORMAT: This is the standard backup
process made by the backup commands a available in the
DBMS such as the SQL backup & restore command.

2. LOGICAL BACKUPS:
 logical backups contain logical data in software mode in a
standard system & it’s not stored in a backup device or
back up utilities. (for example, tables and stored
procedures) extracted with the DBMS backup utilities. We
can use logical backups to supplement physical backups.
DATABASE MANAGEMENT SYSTEMS (DBMS II)
►What is Database recovery ?
Database recovery is the process of restoring the database to a correct state
following a failure. The failure may be the result of a system crash due to
hardware or software errors, a media failure, such asa head crash, or a
software error in the application, such as a logical error in the program that is
accessing the database. It may also be the result of unintentional or
intentional corruption or destruction of data.
DATABASE MANAGEMENT SYSTEMS (DBMS II)
 Data Storage The storage of data generally includes four different types of
media with an increasing degree of reliability. These are:
1. Main memory
2. Magnetic disk
3. Magnetic tape
4. Optical disk
►Stable Storage is the storage in which information is never lost. Stable
storage devices are the theoretically impossible to obtain. But, we must use
some technique to design a storage system in which the chances of data loss
are extremely low.
►Implementation of Storage such as RAID (Redundant Array of Independent
Disk) is commonly used. In case of RAID, information is replicated on several
disks in form of array and each disk has independent failure modes. So, in
this case failure of single disk does not result in loss of data. RAID system
however cannot prevent data loss in case natural disasters like fires or
flooding.
DATABASE MANAGEMENT SYSTEMS (DBMS II)
►What do we mean by Recovery from failure in DBMS:
❖ Actions taken during normal transaction processing to ensure enough
information exists & returned to it’s prior state before failure.
❖ Actions taken following a failure to recover the database to a state that
is known to be correct.
There are two techniques for recovery:
1. Deferred Database Recovery Modification
2. Immediate Database Modification
❖ Deferred Database Modification:
It means that in this case during write operation the modified values of local
variable are not copied into database backup devices immediately but
according to time frame placed by the DATABASE administrators , but the
corresponding new and old values are stored in the PC OR SERVER
WHERE THE DBMS IS LOCATED. But when the transaction successfully
performed all the operations, then the information stored at log record is used
to set the value of data items
DATABASE MANAGEMENT SYSTEMS (DBMS II)
❖ Immediate Database Modification:
❖ It means that in this case during write operation the modified values of local
variable are copied into database items backup devices immediately & the
corresponding new and old values are also stored in the PC OR SERVER
WHERE THE DBMS IS LOCATED.
DATABASE MANAGEMENT SYSTEMS (DBMS II)
► What is the difference between Backup & restore?
►Restoring and Recovering a Database:
►Backup is the process where we create a copies of an existing data in
order to use them when data loss happens.
►Restoring is the process where we Restore or reuse those copies of data
that have been made during the backup process.
►Common problems of backup & recovery:
►Or Causes of backup failures :
Several problems can halt the normal backup operation of a database or affect database I/O
backup operations. The following are the most common types of problems.
1. Media Failure
2. User Error
3. Database Instance Failure
4. Statement Failure
5. Process Failure
6. Network Failure
DATABASE MANAGEMENT SYSTEMS (DBMS II)
1. Media Failure:
► An error can occur when we are trying to write or read a file on disk that is
required to by the backup process on database. This occurrence is called
media failure because there is a physical problem reading or writing to files
on the storage medium.
► A common example of media failure is a disk head crash that causes the
loss of all database files on a disk drive. All files associated with a database
are vulnerable to a disk crash, including data files, control files, online redo
logs, and archived logs.
►The appropriate recovery from a media failure depends on the files affected.
Media failure is the primary concern of a backup and recovery strategy,
because it typically requires restoring some or all database files and the
application of DATABASE during recovery.
DATABASE MANAGEMENT SYSTEMS (DBMS II)
2. User Error
As an administrator, We can do little to prevent user errors such as
accidentally dropping a table. Often, user error can be reduced by increased
training on database and application principles .We can also avoid user
errors by administering privileges correctly so that users are able to do less
potential damage. Furthermore, by planning an effective recovery
scheme ahead of time, We can ease the work necessary to recover from
user errors.
3. Database Failure: Database instance failure occurs when a problem
prevents an SQL database instance from continuing to run. An instance
failure can result from a hardware problem, such as a power outage, or a
software problem, such as an operating system crash. Instance failure also
results when We issue a SHUTDOWN ABORT or STARTUP FORCE.
4. Statement Failure : Statement failure occurs when there is a logical failure
in the handling of a statement in an SQL program. For example, assume that
all extents of a table (in other words, the number of extents specified in the
NAME parameter of the CREATE TABLE statement) are allocated, and are
completely filled with data. Or for example A valid INSERT statement cannot
insert a row because no space is available. Therefore, the statement fails.
DATABASE MANAGEMENT SYSTEMS (DBMS II)
If a statement failure occurs, then the SQL software or operating system returns
an error. A statement failure usually requires no recovery steps: SQL
automatically corrects for statement failure by rolling back any effects of the
statement and returning control to the application.
The user can simply re-execute the statement after the problem indicated by
the error message is corrected. For example, if insufficient extents are
allocated, then the DBA needs to allocate more extents so that the user's
statement can execute.
5. Process Failure
A process failure is a failure in a user, server, or background process of a
database instance such as an abnormal disconnect or process termination.
When a process failure occurs, the failed subordinate process cannot
continue or work, although the other processes of the database instance can
continue.
DATABASE MANAGEMENT SYSTEMS (DBMS II)
6. Network Failure
When your system uses networks such as local area networks and phone
lines to connect client workstations to database servers, or to connect
several database servers to form a distributed database system, network
failures such as aborted phone connections or network communication
software failures can interrupt the normal operation of a database system.
For example:
• A network failure can interrupt normal execution of a client application and
cause a process failure to occur. In this case, the SQL background process it
detects and resolves the aborted server process for the disconnected user
process, as described in the previous section.
DATABASE MANAGEMENT
SYSTEMS (DBMS II)

END of CHAPTER 01
TRANSACTION MANAGEMENT
&
CONCURRENCY CONTROL
THANK YOU FOR YOUR TIME
DATABASE MANAGEMENT SYSTEMS (DBMS II)

You might also like