You are on page 1of 23

CHAPTER 5 DFC 2033

DATABASE TRANSACTION Database


MANAGEMENT
FP304 DATABASE SYSTEM
System
COURSE LEARNING
OUTCOME
CLO2 : Develop a database using a
concurrency control and data
recovery technique based on
Database Management System
(DBMS). (P3, C3, PLO2, PLO1)
LEARNING OUTCOME
FOR TODAY
Demonstrate database transaction
management
Describe transaction system.
Identify the transaction processing systems
category:
a) Batch transaction processing system
b) On-line transaction processing system
(OLTP)
c) Real time transaction processing system.
Describe the properties of database
transaction: Atomicity, Consistency, Isolation,
Durability
Perform transaction of a given database using
SQL statements.
Use START TRANSACTION and COMMIT
LEARNING OUTCOME
FOR TODAY
Describe the concurrency control:
a. Lost update
b. Uncommitted data
c. Inconsistent retrieval
d. The scheduler
Define the Concurrency control with locking
methods:
a. Lock Granularity
b. Lock Types
c. Two Phase Locking to ensure serializability
d. Deadlocks
Explain database recovery management:
a. Database recovery
b. Transaction recovery
c. Database back-up
WHAT IS
TRANSACTION ?
A transaction is a unit of work that should be processed
reliably without interference from other users and
without loss of data due to failures.
Transaction is a completed PROCESS.
Examples of transactions are withdrawing cash at an
ATM, making an airline reservation and registering for a
course.
IDENTIFY THE TRANSACTION
PROCESSING SYSTEMS
CATEGORY

a) Batch transaction processing system


b) On-line transaction processing system
(OLTP)
c) Real time transaction processing
system.
PROPERTIES OF DB
TRANSACTION MANAGEMENT
EXAMPLE OF
TRANSACTION
EXAMPLE OF
TRANSACTION
EXAMPLE OF
TRANSACTION
TRANSACTION STATE
TRANSACTION
MANAGEMENT IN DBMS
CONCURRENCY
CONTROL
Concurrency control is the problem of
synchronizing concurrent transactions (i.e., order
the operations of concurrent transactions) such
that the following two properties are achieved:
the consistency of the DB is maintained
the maximum degree of concurrency of
operations is achieved
CONCURRENCY
CONTROL
The purpose of concurrency control is to
prevent two different users (or two
different connections by the same user)
from trying to update the same data at the
same time. Concurrency control can also
prevent one user from seeing out-of-date
data while another user is updating the
same data.
CONCURRENCY
CONTROL
The following examples explain why concurrency control is
needed. For both examples, suppose that your checking account
contains $1,000. During the day you deposit $300 and spend
$200 from that account. At the end of the day your account
should have $1,100.
Example 1: No concurrency control
At 11:00 AM, bank teller #1 looks up your account and sees that
you have $1,000. The teller subtracts the $200 check, but is not
able to save the updated account balance ($800) immediately. At
11:01 AM, another teller #2 looks up your account and still sees
the $1,000 balance. Teller #2 then adds your $300 deposit and
saves your new account balance as $1,300. At 11:09 AM, bank
teller #1 returns to the terminal, finishes entering and saving the
updated value that is calculated to be $800. That $800 value
writes over the $1300. At the end of the day, your account has
$800 when it should have had $1,100 ($1000 + 300 - 200).
Example 2: Concurrency control
When teller #1 starts working on your account, a lock is placed on
CONCURRENCY
CONTROL
Interference problem arise from simultaneous access to
database:
Lost Update
Uncommitted Dependency
Inconsistent Retrieval
LOST UPDATE
Successfully completed update is overridden by
another user.
Lost updates occur when two or more transactions
select the same row and then update the row based on
the value originally selected.
Each transaction is unaware of other transactions. The
last updates overwrites updates made by the other
transactions which results in lost data.
UNCOMMITTED
DEPENDENCY
Occurs when one transaction can see intermediate
results of another transaction before it has committed.
Uncommitted dependency occurs when a second
transaction selects a row that is being updated by
another transaction.
The second transaction is reading data that has not
been committed yet and may be changed by the
transaction updating the row.
INCONSISTENT
RETRIEVAL
Occurs when transaction reads several values but
second transaction updates some of them during
execution of first.
DATABASE
CONCURRENCY
CONTROL
Two-Phase Locking Techniques -The algorithm
(a) Locking (Growing)
(b) Unlocking (Shrinking).
Locking (Growing) Phase: A transaction applies locks (read or
write) on desired data items one at a time.
Unlocking (Shrinking) Phase: A transaction unlocks its locked
data items one at a time.
Requirement:
For a transaction these two phases must be mutually
exclusively, that is, during locking phase unlocking phase
must not start and during unlocking phase locking phase must
not begin.
TYPE OF LOCK
Binary lock has 2 states as locked and unlocked. 1 is
used for representing locked status and 0 is used for
representing unlocked status.
Exclusive Lock Access is specifically reserved for the
transaction that locked the object. Granted if and only
if no other locks are held on the data item.
Shared Lock Concurrent transactions are granted
Read access on the basis of a common lock. Issued
when a transaction wants to read data and no
exclusive lock is held on that data item. Multiple
transactions can each have a shared lock on the same
data item if they are all just reading it.
TYPES OF RECOVERY
TOOLS
Transaction Log
A table that contains a history of database changes. The recovery
manager uses the log table to recover from failures.

Checkpoint
The act of writing a checkpoint to log and writing log and database
buffer to disk.

Database Backup
A copy of all or part of disk. Is used when the disk containing the
database or log is damaged.
TYPES OF DATABASE
BACKUP
Full Backup
Full copy/backup of entire data set. Time consuming and require a
large number of tapes or disk.

Incremental Backup
Introduced as a way of decreasing the amount of time because full
backup is time consuming. Backup the data that has changes since
the previous backup.

Differential Backup
Similar to incremental backup, starts with a full backup and
subsequent backup only includes the data that has changed since
the last full backup.

You might also like