Professional Documents
Culture Documents
Chapter 5
Chapter 5
DATABASE DESIGN
CHAPTER 5
DATABASE TRANSACTION MANAGEMENT
COURSE LEARNING OUTCOME
https://www.techopedia.com/definition/707/transaction-process-system-tps
TRANSACTION SYSTEM CATEGORY
BATCH
• Batch processing is where the information is collected
TRANSACTIO and stored as a batch but not processed immediately.
N • Useful for enterprises that need to process large
amounts of data using limited resources.
PROCESSING • Example: credit card transactions.
SYSTEM
ONLINE
TRANSACTIO • A system whereby each transaction is processed
N immediately without the delay of accumulating
transactions into a batch.
PROCESSING • Also known as real time transaction processing system.
• Example: online shopping transaction, ATM, PayPal.
SYSTEM
(OLTP)
CONCURRENCY CONTROL
• The coordination of the simultaneous execution
of transactions in a multiprocessing database is
known as concurrency control.
Interference Problems
• Three problems that can result because of simultaneous access to a
database:
(1) lost update,
(2) uncommitted dependency / uncommitted data
(3) inconsistent retrieval.
NORMAL EXECUTION OF TWO
TRANSACTIONS
INTERFERENCE PROBLEMS :
LOST UPDATE
• Lost update is the most serious interference problem
because changes to a database are inadvertently lost.
• In a lost update, one user's update overwrites another
user's update.
INTERFERENCE PROBLEMS:
UNCOMMITTED DEPENDENCY
• An uncommitted dependency occurs when one
transaction reads data written by another transaction
before the other transaction commits.
• An uncommitted dependency is also known as a dirty
read because it is caused by one transaction reading dirty
(uncommitted) data.
• Violates the isolation property of transaction.
CORRECT EXECUTION OF TWO TRANSACTIONS
AN UNCOMMITTED DEPENDENCY
PROBLEM
INCONSISTENT RETRIEVAL PROBLEM
‘1558-QW1’
THE SCHEDULER
• The scheduler is a special DBMS process that establishes the order
in which the operations are executed within concurrent
transactions.
• The scheduler interleaves the execution of database operations to
ensure serializability and isolation of transactions.
• To determine the appropriate order, the scheduler bases its actions
on concurrency control algorithms, such as locking or time stamping
methods.
• The scheduler’s main job is to create a serializable schedule of a
transaction’s operations, in which the interleaved execution of
the transactions (T1, T2, T3, etc.) yields the same results as if the
transactions were executed in serial order (one after another).
T1 and T2 can access the same database concurrently as long as they use
different tables.
Can cause bottlenecks when many transactions are trying to access the same
table (even if the transactions want to access different parts of the table and would
not interfere with each other).
Not suitable for multi-user DBMSs.
PAGE-LEVEL LOCK
An entire disk page is locked (a table can span several pages and each
page can contain several rows of one or more tables).
Most frequently used multi-user DBMS locking method.
ROW-LEVEL LOCK
• A deadlock is a problem of mutual waiting. One transaction has a resource that a second
transaction needs, and the second transaction holds a resource that the first transaction needs.
• For example, a deadlock occurs when two transactions, T1 and T2, exist in the following
mode:
• If T1 has not unlocked data item Y, T2 cannot begin; if T2 has not unlocked data item X, T1
cannot continue. Consequently, T1 and T2 each wait for the other to unlock the required data
DEADLOCK
CONTROL
2 Human-caused incidents
• This type of event can be categorized as unintentional or intentional.
• An unintentional failure is caused by a careless end user. Such errors include deleting the wrong rows from a table,
pressing the wrong key on the keyboard, or shutting down the main database server by accident.
• Intentional events are of a more severe nature and normally indicate that the company data is at serious risk.
Under this category are security threats caused by hackers trying to gain unauthorized access to data resources
and virus attacks caused by individuals trying to compromise the database operation and damage the company.
3 Natural disasters
• fires, earthquakes, floods, and power failures.
TRANSACTION Log
– If a system failure occurs, the DBMS will examine the log for all
uncommitted or incomplete transactions and it will restore (ROLLBACK)
the database to a previous state
– When the recovery process is completed, the DBMS will write in the
log all committed transactions that were not physically written to the
database before the failure occurred.
TRANSACTION RECOVERY
• Database transaction recovery uses data in the
transaction log to recover a database from an
inconsistent state to a consistent state.
• Four important concepts that affect the recovery process:
1. Write-ahead-log protocol
2. Redundant transaction logs
3. Database buffers
4. Database checkpoints
TRANSACTION RECOVERY
• The write-ahead-log protocol ensures that transaction
logs are always written before any database data is
actually updated. This protocol ensures that, in case of a
failure, the database can later be recovered to a
consistent state using the data in the transaction log.
• Redundant transaction logs (several copies of the
transaction log) ensure that a physical disk failure will not
impair the DBMS’s ability to recover data.
TRANSACTION RECOVERY
• Database buffers are temporary storage areas in primary memory
used to speed up disk operations.
• To improve processing time, the DBMS software reads the data from
the physical disk and stores a copy of it on a “buffer” in primary
memory.
• When a transaction updates data, it actually updates the copy of the
data in the buffer because that process is much faster than
accessing the physical disk every time.
• Later, all buffers that contain updated data are written to a physical
disk during a single operation, thereby saving significant processing
time.
TRANSACTION RECOVERY
• Database checkpoints are operations in which the DBMS writes all
of its updated buffers in memory (also known as dirty buffers) to
disk. While this is happening, the DBMS does not execute any other
requests.
• A checkpoint operation is also registered in the transaction log.
• As a result of this operation, the physical database and the
transaction log will be in sync.
• This synchronization is required because update operations update
the copy of the data in the buffers and not in the physical database.
TRANSACTION RECOVERY
• Transaction recovery procedures generally make use of deferred-
write and write-through techniques.
• When the recovery procedure uses a deferred-write technique
(also called a deferred update), the transaction operations do not
immediately update the physical database. Instead, only the
transaction log is updated.
• The database is physically updated only with data from committed
transactions, using information from the transaction log.
• If the transaction aborts before it reaches its commit point, no
changes (no ROLLBACK or undo) need to be made to the database
because it was never updated.
TRANSACTION RECOVERY
• When the recovery procedure uses a write-through technique (also
called an immediate update), the database is immediately updated
by transaction operations during the transaction’s execution, even
before the transaction reaches its commit point.
• If the transaction aborts before it reaches its commit point, a
ROLLBACK or undo operation needs to be done to restore the
database to a consistent state.
• In that case, the ROLLBACK operation will use the transaction log
“before” values.
DATABASE BACKUP
• A backup is a copy of all or part of a disk. The backup is used when
the disk containing the database or log is damaged.
• A backup is usually made on magnetic tape because it is less
expensive and more reliable than disk.
• Periodically, a backup should be made for both the database and the
log. To save time, most backup schedules include less frequent
massive backups to copy the entire contents of a disk and more
frequent incremental backups to copy only the changed part.
DATABASE BACKUP
• Types of backup:
–Periodic backup (e.g. nightly, weekly)
–Cold backup – database is shut down during
backup.
–Hot backup – selected portion is shut down
and backed up at a given time.
DATABASE BACKUP
– Full backup: Full backup is a method of backup where all the
files and folders selected for the backup will be backed up.
When subsequent backups are run, the entire list of files and will
be backed up again.
– Incremental backup: Incremental backup is a backup of all
changes made since the last backup. With incremental backups,
one full backup is done first and subsequent backup runs are
just the changes made since the last backup.
– Example of incremental backup: For example, suppose that
you created a full backup on Monday, and used incremental
backups for the rest of the week. Tuesday's backup would only
contain the data that has changed since Monday. Wednesday's
backup would only contain the data that has changed since
Tuesday.
DATABASE BACKUP
– Differential backup: Differential backup is a backup of all
changes made since the last full backup. With differential
backups, one full backup is done first and subsequent backup
runs are the changes made since the last full backup.
– Example of differential backup: Suppose for example that you
wanted to create a full backup on Monday and differential
backups for the rest of the week. Tuesday's backup would
contain all of the data that has changed since Monday. It would
therefore be identical to an incremental backup at this point. On
Wednesday, however, the differential backup would backup any
data that had changed since Monday.
SUMMARY
• TRANSACTION SYSTEM.
• CATEGORY OF TRANSACTION SYSTEM.
• PROPERTIES OF TRANSACTION: ACID.
• SQL TCL STATEMENTS: START TRANSACTION, COMMIT, ROLLBACK.
• CONCURRENCY CONTROL.
• SIMULTANEOUS EXECUTION OF TRANSACTION PROBLEMS: LOST
UPDATE, UNCOMMITTED DATA & INCONSISTENT RETRIEVAL.
• LOCK METHOD.
• DEADLOCK PROBLEM.
• DATABASE RECOVERY MANAGEMENT.