9 1 Chapter 9 Transaction Management and Concurrency Control Database Systems: Design, Implementation, and Management, Sixth Edition, Rob and Coronel.

Slides:



Advertisements
Similar presentations
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 Transaction Management Overview Chapter 16.
Advertisements

CSC271 Database Systems Lecture # 32.
Lecture 11 Recoverability. 2 Serializability identifies schedules that maintain database consistency, assuming no transaction fails. Could also examine.
Database Systems, 8 th Edition Concurrency Control with Time Stamping Methods Assigns global unique time stamp to each transaction Produces explicit.
Transaction Management and Concurrency Control
10 1 Chapter 10 Transaction Management and Concurrency Control Database Systems: Design, Implementation, and Management, Seventh Edition, Rob and Coronel.
Transaction Management and Concurrency Control
Transaction Management and Concurrency Control
Transaction Management and Concurrency Control
Database Systems: Design, Implementation, and Management Eighth Edition Chapter 10 Transaction Management and Concurrency Control.
What is a Transaction? Logical unit of work
Transaction Management
Chapter 9 Transaction Management and Concurrency Control
9 Chapter 9 Transaction Management and Concurrency Control Hachim Haddouti.
Database Administration Part 1 Chapter Six CSCI260 Database Applications.
Database Systems: Design, Implementation, and Management Eighth Edition Chapter 10 Transaction Management and Concurrency Control.
Transaction Management and Concurrency Control
Transaction Management Chapter 9. What is a Transaction? A logical unit of work on a database A logical unit of work on a database An entire program An.
Client/Server Databases and the Oracle 10g Relational Database
Multi-user Database Processing Architectures Architectures Transactions Transactions Security Security Administration Administration.
1 Transaction Management Overview Chapter Transactions  Concurrent execution of user programs is essential for good DBMS performance.  Because.
Database Management Systems, 2 nd Edition. R. Ramakrishnan and J. Gehrke1 Transaction Management Overview Chapter 18.
1 Transactions BUAD/American University Transactions.
Recovery & Concurrency Control. What is a Transaction?  A transaction is a logical unit of work that must be either entirely completed or aborted. 
Security and Transaction Nhi Tran CS 157B - Dr. Lee Fall, 2003.
Database Systems: Design, Implementation, and Management Tenth Edition
BIS Database Systems School of Management, Business Information Systems, Assumption University A.Thanop Somprasong Chapter # 10 Transaction Management.
Chapter 9 Transaction Management and Concurrency Control Database Systems: Design, Implementation and Management Peter Rob & Carlos Coronel.
Chapterb19 Transaction Management Transaction: An action, or series of actions, carried out by a single user or application program, which reads or updates.
Database Management Systems, 2 nd Edition. R. Ramakrishnan and J. Gehrke1 Transaction Management Overview Lecture 21 Ramakrishnan - Chapter 18.
Databases Illuminated
ITEC 3220M Using and Designing Database Systems Instructor: Prof. Z. Yang Course Website: 3220m.htm
Chapter 15 Recovery. Topics in this Chapter Transactions Transaction Recovery System Recovery Media Recovery Two-Phase Commit SQL Facilities.
Database Systems/COMP4910/Spring05/Melikyan1 Transaction Management Overview Unit 2 Chapter 16.
1 Chapter 20 Transaction Management Transparencies Last Updated: 17 th March 2011 By M. Arief
Ch 10: Transaction Management and Concurrent Control.
Chapter 9 Transaction Management and Concurrency Control Database Systems: Design, Implementation and Management Peter Rob & Carlos Coronel.
11/7/2012ISC329 Isabelle Bichindaritz1 Transaction Management & Concurrency Control.
Chapter 15 Recovery. Copyright © 2004 Pearson Addison-Wesley. All rights reserved.15-2 Topics in this Chapter Transactions Transaction Recovery System.
Transactions and Locks A Quick Reference and Summary BIT 275.
II.I Selected Database Issues: 2 - Transaction ManagementSlide 1/20 1 II. Selected Database Issues Part 2: Transaction Management Lecture 4 Lecturer: Chris.
The Relational Model1 Transaction Processing Units of Work.
Chapter 20 Transaction Management Thomas Connolly, Carolyn Begg, Database System, A Practical Approach to Design Implementation and Management, 4 th Edition,
Transaction Management Transparencies. ©Pearson Education 2009 Chapter 14 - Objectives Function and importance of transactions. Properties of transactions.
ITEC 3220A Using and Designing Database Systems Instructor: Gordon Turpin Course Website: Office: CSEB3020.
1 Advanced Database Concepts Transaction Management and Concurrency Control.
Overview of Transaction Management
Transaction Management and Concurrent Control
9 1 Chapter 9_B Concurrency Control Database Systems: Design, Implementation, and Management, Rob and Coronel.
NOEA/IT - FEN: Databases/Transactions1 Transactions ACID Concurrency Control.
10 1 Chapter 10_B Concurrency Control Database Systems: Design, Implementation, and Management, Rob and Coronel.
Database Systems: Design, Implementation, and Management Eighth Edition Chapter 10 Transaction Management and Concurrency Control.
10 Transaction Management and Concurrency Control MIS 304 Winter 2005.
©Bob Godfrey, 2002, 2005 Lecture 17: Transaction Integrity and Concurrency BSA206 Database Management Systems.
3 Database Systems: Design, Implementation, and Management CHAPTER 9 Transaction Management and Concurrency Control.
10 1 Chapter 10 - A Transaction Management Database Systems: Design, Implementation, and Management, Rob and Coronel.
18 September 2008CIS 340 # 1 Last Covered (almost)(almost) Variety of middleware mechanisms Gain? Enable n-tier architectures while not necessarily using.
Chapter 13 Managing Transactions and Concurrency Database Principles: Fundamentals of Design, Implementation, and Management Tenth Edition.
Transactions and Concurrency Control. 2 What is a Transaction?  Any action that reads from and/or writes to a database may consist of  Simple SELECT.
SYSTEMS IMPLEMENTATION TECHNIQUES TRANSACTION PROCESSING DATABASE RECOVERY DATABASE SECURITY CONCURRENCY CONTROL.
Transaction Management and Concurrency Control
Transaction Management Transparencies
Transaction Management
Transaction Properties
Chapter 10 Transaction Management and Concurrency Control
Chapter 10 Transaction Management and Concurrency Control
Chapter 9 Transaction Management and Concurrency Control
Introduction of Week 13 Return assignment 11-1 and 3-1-5
Transactions, Properties of Transactions
Presentation transcript:

9 1 Chapter 9 Transaction Management and Concurrency Control Database Systems: Design, Implementation, and Management, Sixth Edition, Rob and Coronel

9 2 Database Systems: Design, Implementation, & Management, 6 th Edition, Rob & Coronel In this chapter, you will learn: What a database transaction is and what its properties are How database transactions are managed What concurrency control is and what role it plays in maintaining the database’s integrity What locking methods are and how they work How database recovery management is used to maintain database integrity

9 3 Database Systems: Design, Implementation, & Management, 6 th Edition, Rob & Coronel 9.1 What is a Transaction? A transaction is any action that reads from and/or writes to a database may consist of –Simple SELECT statement to generate a list of table contents –A series of related UPDATE statements to change the values of attributes in various tables –A series of INSERT statements to add rows to one or more tables –A series of DELETE statements to add rows to one or more tables –A combination of SELECT, UPDATE, INSERT, and DELETE statements

9 4 Database Systems: Design, Implementation, & Management, 6 th Edition, Rob & Coronel What is a Transaction? ( continued ) A transaction is a logical unit of work that must be either entirely completed or aborted Successful transaction changes the database from one consistent state to another –One in which all data integrity constraints are satisfied Most real-world database transactions are formed by two or more database requests –A request is the equivalent of a single SQL statement in an application program or transaction –Each request generate several I/O operations that read from or write to physical storage media

9 5 Database Systems: Design, Implementation, & Management, 6 th Edition, Rob & Coronel Assume the transactions are semantically correct

9 6 Database Systems: Design, Implementation, & Management, 6 th Edition, Rob & Coronel Evaluating Transaction Results Not all transactions update the database SQL code represents a transaction because database was accessed Improper or incomplete transactions can have a devastating effect on database integrity –Some DBMSs provide means by which user can define enforceable constraints based on business rules –Other integrity rules are enforced automatically by the DBMS when table structures are properly defined, thereby letting the DBMS validate some transactions

9 7 Database Systems: Design, Implementation, & Management, 6 th Edition, Rob & Coronel Figure 9.2

9 8 Database Systems: Design, Implementation, & Management, 6 th Edition, Rob & Coronel Transaction Properties ACID: Atomicity, Consistency, Isolation, Durability Atomicity –Requires that all operations (SQL requests) of a transaction be completed; if not, the transaction is aborted Consistency (called Serializability in this textbook) –Ensures that the concurrent execution of several transactions yields consistent results

9 9 Database Systems: Design, Implementation, & Management, 6 th Edition, Rob & Coronel Transaction Properties ( continued ) Isolation –Data used during execution of a transaction cannot be used by a second transaction until the first one is completed Durability –Indicates permanence of database’s consistent state

9 10 Database Systems: Design, Implementation, & Management, 6 th Edition, Rob & Coronel Transaction Management with SQL ANSI has defined standards that govern SQL database transactions Transaction support is provided by two SQL statements: COMMIT and ROLLBACK ANSI standards require that, when a transaction sequence is initiated by a user or an application program, –it must continue through all succeeding SQL statements until one of four events occurs 1.A COMMIT is reached 2.A ROLLBACK is reached 3.The end of program is successfully reached 4.The program is abnormally terminated

9 11 Database Systems: Design, Implementation, & Management, 6 th Edition, Rob & Coronel The Transaction Log It is for recovery triggered by a ROLLBACK, a program’s abnormal termination, or a system failure –After a server failure, Oracle automatically rolls back uncommitted transactions and rolls forward transactions committed but not written to storage The transaction log stores –A record for the beginning of transaction –For each transaction component (SQL statement) Type of operation being performed (update, delete, insert) Names of objects affected by the transaction (the name of the table) “Before” and “after” values for updated fields Pointers to previous and next transaction log entries for the same transaction –The ending (COMMIT) of the transaction

9 12 Database Systems: Design, Implementation, & Management, 6 th Edition, Rob & Coronel

9 13 Database Systems: Design, Implementation, & Management, 6 th Edition, Rob & Coronel 9.2 Concurrency Control Coordination of simultaneous transaction execution in a multiprocessing database system Objective is to ensure transaction serializability in a multi-user database environment

9 14 Database Systems: Design, Implementation, & Management, 6 th Edition, Rob & Coronel Concurrency Control –Important : simultaneous execution of transactions over a shared database can create several data integrity and consistency problems when no concurrency control is imposed lost updates uncommitted data inconsistent retrievals

9 15 Database Systems: Design, Implementation, & Management, 6 th Edition, Rob & Coronel

9 16 Database Systems: Design, Implementation, & Management, 6 th Edition, Rob & Coronel

9 17 Database Systems: Design, Implementation, & Management, 6 th Edition, Rob & Coronel

9 18 Database Systems: Design, Implementation, & Management, 6 th Edition, Rob & Coronel Violation of isolation

9 19 Database Systems: Design, Implementation, & Management, 6 th Edition, Rob & Coronel

9 20 Database Systems: Design, Implementation, & Management, 6 th Edition, Rob & Coronel

9 21 Database Systems: Design, Implementation, & Management, 6 th Edition, Rob & Coronel

9 22 Database Systems: Design, Implementation, & Management, 6 th Edition, Rob & Coronel The Scheduler The scheduler is a special DBMS program: establishes order of operations within which concurrent transactions are executed It interleaves the execution of database operations to ensure serializability and isolation of transactions

9 23 Database Systems: Design, Implementation, & Management, 6 th Edition, Rob & Coronel The Scheduler ( continued ) It bases its actions on concurrency control algorithms, like locking or time stamping Ensures computer’s central processing unit (CPU) is used efficiently Facilitates data isolation to ensure that two transactions do not update the same data element at the same time

9 24 Database Systems: Design, Implementation, & Management, 6 th Edition, Rob & Coronel

9 25 Database Systems: Design, Implementation, & Management, 6 th Edition, Rob & Coronel 9.3 Concurrency Control with Locking Methods Lock –Guarantees exclusive use of a data item to a current transaction A transaction acquires lock prior to data access; the lock is released (unlocked) when the transaction is completed –Required to prevent another transaction from reading inconsistent data Lock manager –Responsible for assigning and policing the locks used by the transactions

9 26 Database Systems: Design, Implementation, & Management, 6 th Edition, Rob & Coronel Lock Granularity Indicates the level of lock use Locking can take place at the following levels: –Database –Table –Page –Row –Field (attribute)

9 27 Database Systems: Design, Implementation, & Management, 6 th Edition, Rob & Coronel Lock Granularity ( continued ) Database-level lock –Entire database is locked, good for batch processes Table-level lock –Entire table is locked, not suitable for mutiuser DBMSs Page-level lock –Entire diskpage is locked, most frequently used –A table may span several pages, and a page may contain several rows of one or more tables

9 28 Database Systems: Design, Implementation, & Management, 6 th Edition, Rob & Coronel Lock Granularity ( continued ) Row-level lock –Allows concurrent transactions to access different rows of the same table, even if the rows are located on the same page –Its management requires high overhead cost Field-level lock –Allows concurrent transactions to access the same row, as long as they require the use of different fields (attributes) within that row –Rarely done because of extremely high overhead

9 29 Database Systems: Design, Implementation, & Management, 6 th Edition, Rob & Coronel

9 30 Database Systems: Design, Implementation, & Management, 6 th Edition, Rob & Coronel

9 31 Database Systems: Design, Implementation, & Management, 6 th Edition, Rob & Coronel

9 32 Database Systems: Design, Implementation, & Management, 6 th Edition, Rob & Coronel

9 33 Database Systems: Design, Implementation, & Management, 6 th Edition, Rob & Coronel Lock Types Binary lock –Has only two states: locked (1) or unlocked (0) –Too restrictive Exclusive lock –Access is specifically reserved for the transaction that locked the object –Must be used when the potential for conflict exists –Mutual exclusive rule: only one transaction at a time can own an exclusive lock on the same object Shared lock –Concurrent transactions are granted Read access on the basis of a common lock

9 34 Database Systems: Design, Implementation, & Management, 6 th Edition, Rob & Coronel

9 35 Database Systems: Design, Implementation, & Management, 6 th Edition, Rob & Coronel Shared / Exclusive Locks A shared/exclusive lock schema increases the lock manager’s overhead in –The type of lock held must be known before a lock can be granted –Three lock operations exist: READ_LOCK, WRITE_LOCK, and UNLOCK –The schema has been enhanced to allow a lock upgrade or a lock downgrade Major problems of locks –The resulting schedule may not be serializable (example: inconsistent retrieval) –The schedule may create deadlocks

9 36 Database Systems: Design, Implementation, & Management, 6 th Edition, Rob & Coronel Two-Phase Locking to Ensure Serializability Defines how transactions acquire and relinquish locks Guarantees serializability, but it does not prevent deadlocks. The two phases are –Growing phase, in which a transaction acquires all the required locks without unlocking any data –Shrinking phase, in which a transaction releases all locks and cannot obtain any new lock

9 37 Database Systems: Design, Implementation, & Management, 6 th Edition, Rob & Coronel Two-Phase Locking to Ensure Serializability ( continued ) Governed by the following rules: –Two transactions cannot have conflicting locks –No unlock operation can precede a lock operation in the same transaction –No data are affected until all locks are obtained—that is, until the transaction is in its locked point

9 38 Database Systems: Design, Implementation, & Management, 6 th Edition, Rob & Coronel

9 39 Database Systems: Design, Implementation, & Management, 6 th Edition, Rob & Coronel Deadlocks Condition that occurs when two transactions wait for each other to unlock data Possible only if one of the transactions wants to obtain an exclusive lock on a data item –No deadlock condition can exist among shared locks Control through –Prevention: recommended if the deadlock probability is high –Detection: recommended if the deadlock probability is low –Avoidance: obtains all locks before it can be executed. Might be employed If response time is not high on the system priority list.

9 40 Database Systems: Design, Implementation, & Management, 6 th Edition, Rob & Coronel

9 41 Database Systems: Design, Implementation, & Management, 6 th Edition, Rob & Coronel 9.4 Concurrency Control with Time Stamping Methods Assigns a global unique time stamp to each transaction Produces an explicit order in which transactions are submitted to the DBMS Must have two properties –Uniqueness : Ensures that no equal time stamp values can exist –Monotonicity : Ensures that time stamp values always increase

9 42 Database Systems: Design, Implementation, & Management, 6 th Edition, Rob & Coronel Concurrency Control with Time Stamping Methods All database operations within the same transaction must have the same time stamp DBMS executes conflicting operations in time stamp order If two transactions conflict, one is stopped, rolled back, rescheduled, and assigned a new time stamp Each value stored in the database requires two additional time stamp fields: –One for the last the value was read, and one for the last update

9 43 Database Systems: Design, Implementation, & Management, 6 th Edition, Rob & Coronel Wait/Die and Wound/Wait Schemes Wait/die –If the transaction requesting the lock (operation) is the older one, the older transaction waits until the other is completed –If the transaction requesting the lock is the younger one, the younger transaction dies (is rolled back) and rescheduled using the same time stamp Wound/wait –If the transaction requesting the lock is the older one, the older transaction will preempt (wound) the younger one. The younger one is rescheduled with the same transaction. –If the transaction requesting the lock is the younger one, the younger transaction waits until th eolder one is completed

9 44 Database Systems: Design, Implementation, & Management, 6 th Edition, Rob & Coronel 訂正 : If the lock is not granted before the time-out expires, the transaction is rolled back.

9 45 Database Systems: Design, Implementation, & Management, 6 th Edition, Rob & Coronel 9.5 Concurrency Control with Optimistic Methods Optimistic approach –Based on the assumption that the majority of database operations do not conflict –Does not require locking or time stamping techniques –Transaction is executed without restrictions until it is committed –Phases are read, validation, and write

9 46 Database Systems: Design, Implementation, & Management, 6 th Edition, Rob & Coronel Concurrency Control with Optimistic Methods –During the read phase, the transaction reads the database, executes the needed computations, and makes the update to a private copy of the database value –During the validation phase, the transaction is validated to ensure that the changes made will not affect the integrity and consistency of the database –During the write phase, the changes are permanently applied to the database Useful for mostly read, very few update transactions

9 47 Database Systems: Design, Implementation, & Management, 6 th Edition, Rob & Coronel 9.6 Database Recovery Management Database recovery –Restores database from a given state, usually inconsistent, to a previously consistent state –Based on the atomic transaction property All portions of the transaction must be treated as a single logical unit of work, in which all operations must be applied and completed to produce a consistent database –If transaction operation cannot be completed, transaction must be aborted, and any changes to the database must be rolled back (undone)

9 48 Database Systems: Design, Implementation, & Management, 6 th Edition, Rob & Coronel Database Recovery Management The level of backup –Full backup –Differential backup –Transaction log backup Database backup is stored in a secure, protected different building Failures that plague databases and systems are induced by –Software, Hardware, Programming exemption, Transaction, or External factors

9 49 Database Systems: Design, Implementation, & Management, 6 th Edition, Rob & Coronel Database Recovery Management Recovery scenario –Determine the type and the extent of the required recovery –If the entire database needs to be recovered, use the most recent backup copy of the database in a known consistent state –The backup copy is rolled forward to restore all subsequent transactions by using transaction log. Use the transaction log to “undo” all the un-committed transactions

9 50 Database Systems: Design, Implementation, & Management, 6 th Edition, Rob & Coronel Transaction Recovery Four important concepts that affect the recovery process –The write-ahead-log protocol Transaction logs are always written before any database data are actually updated –Redundant transaction logs –Database buffers When a transaction updates data, it actually updates the copy of the data in the memory buffer –Database checkpoints An operation in which the DBMS writes all of its updated buffers to disk

9 51 Database Systems: Design, Implementation, & Management, 6 th Edition, Rob & Coronel Transaction Recovery Makes use of deferred-write and write-through Deferred write –Transaction operations do not immediately update the physical database –Only the transaction log is updated –Database is physically updated only after the transaction reaches its commit point using the transaction log information –If the transaction aborts before it reaches its commit point, no change need to be made to the database

9 52 Database Systems: Design, Implementation, & Management, 6 th Edition, Rob & Coronel Deferred Write Its recovery process –Identify the last checkpoint in the transaction log –For a transaction that started and committed before the last checkpoint, nothing needs to be done –For a transaction that performed a commit operation after the last checkpoint, redo the transaction and update the database, applied from the oldest to the newest transactions. –For any transaction with a ROLLBACK operation after the last checkpoint or that was left active (with neither a COMMIT nor a ROLLBACK) before the failure occurred, nothing needs to be done

9 53 Database Systems: Design, Implementation, & Management, 6 th Edition, Rob & Coronel Transaction Recovery ( continued ) Write-through –Database is immediately updated by transaction operations during the transaction’s execution, even before the transaction reaches its commit point –If a transaction aborts before it reaches its commit point, a ROLLBACK or undo operation needs to be done

9 54 Database Systems: Design, Implementation, & Management, 6 th Edition, Rob & Coronel Write-through Its recovery process –Identify the last checkpoint in the transaction log –For a transaction that started and committed before the last checkpoint, nothing needs to be done –For a transaction that performed a commit operation after the last checkpoint, redo the transaction and update the database, applied from the oldest to the newest transactions. –For any transaction with a ROLLBACK operation after the last checkpoint or that was left active (with neither a COMMIT nor a ROLLBACK) before the failure occurred, ROLLBACK or undo the operations, applied from the newest to the oldest transactions.

9 55 Database Systems: Design, Implementation, & Management, 6 th Edition, Rob & Coronel

9 56 Database Systems: Design, Implementation, & Management, 6 th Edition, Rob & Coronel Summary Transaction –Sequence of database operations that access the database –Represents real-world events –Must be a logical unit of work No portion of the transaction can exist by itself –Takes a database from one consistent state to another One in which all data integrity constraints are satisfied

9 57 Database Systems: Design, Implementation, & Management, 6 th Edition, Rob & Coronel Summary ( continued ) SQL provides support for transactions through the use of two statements: COMMIT and ROLLBACK Concurrency control coordinates the simultaneous execution of transactions Scheduler is responsible for establishing order in which concurrent transaction operations are executed

9 58 Database Systems: Design, Implementation, & Management, 6 th Edition, Rob & Coronel Summary ( continued ) Lock guarantees unique access to a data item by a transaction Database recovery restores the database from a given state to a previous consistent state