9 Copyright © 2009, Oracle. All rights reserved. Managing Data Concurrency.

Slides:



Advertisements
Similar presentations
Chapter 16 Concurrency. Topics in this Chapter Three Concurrency Problems Locking Deadlock Serializability Isolation Levels Intent Locking Dropping ACID.
Advertisements

1 Lecture 11: Transactions: Concurrency. 2 Overview Transactions Concurrency Control Locking Transactions in SQL.
Accessing data Transactions. Agenda Questions from last class? Transactions concurrency Locking rollback.
4 Copyright © 2005, Oracle. All rights reserved. Managing the Oracle Instance.
Manipulating Data Schedule: Timing Topic 60 minutes Lecture
Understanding Locks and Enqueues How to Approach Common Blocking Lock Scenarios By Mark J. Bobak November 20 th, 2008.
Transaction Processing. Objectives After completing this lesson, you should be able to do the following: –Define transactions effectively for an application.
9-1 Copyright  Oracle Corporation, All rights reserved. Data Manipulation Language A DML statement is executed when you: – Add new rows to a table.
Allowing Multi-user Access Grant – GRANT ON TO |WITH GRANT OPTION | –GRANT TO | WITH ADMIN OPTION| – can be PUBLIC or a role – can be ALL Revoke – REVOKE.
1 Data Concurrency David Konopnicki 1997 Revised by Mordo Shalom 2004.
ACS R McFadyen 1 Transaction A transaction is an atomic unit of work that is either completed in its entirety or not done at all. For recovery purposes,
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.
Copyright  Oracle Corporation, All rights reserved. 9 Manipulating Data: INSERT, UPDATE, DELETE.
Locking and concurrency. Overview In multi-user systems, several users may update the same information concurrently – i.e. at the same time. Locking allows.
10 Copyright © 2009, Oracle. All rights reserved. Managing Undo Data.
Database Systems: Design, Implementation, and Management Eighth Edition Chapter 10 Transaction Management and Concurrency Control.
Chapter 5 Data Manipulation and Transaction Control Oracle 10g: SQL
2 Copyright © 2004, Oracle. All rights reserved. Creating Stored Functions.
Transaction Management and Concurrency Control
Transaction log grows unexpectedly
Transactions and Locks Lesson 22. Skills Matrix Transaction A transaction is a series of steps that perform a logical unit of work. Transactions must.
4 Copyright © 2004, Oracle. All rights reserved. Database Interfaces.
Allowing Multi-user Access Grant – GRANT ON TO – |WITH GRANT OPTION / WITH ADMIN OPTION| – can be PUBLIC or a role – can be all Revoke – REVOKE ON FROM.
Copyright © 2011 Accenture All Rights Reserved. Accenture, its logo, and High Performance Delivered are trademarks of Accenture. SQL Workshop Day 3.
BIS Database Systems School of Management, Business Information Systems, Assumption University A.Thanop Somprasong Chapter # 10 Transaction Management.
Oracle Locking Michael Messina Principal Database Analyst Indiana University.
9 Copyright © 2007, Oracle. All rights reserved. Managing Data and Concurrency.
16 Copyright © 2004, Oracle. All rights reserved. Undo Management.
Objectives After completing this lesson, you should be able to do the following: Describe each data manipulation language (DML) statement Insert rows.
11/7/2012ISC329 Isabelle Bichindaritz1 Transaction Management & Concurrency Control.
Module 11 Creating Highly Concurrent SQL Server® 2008 R2 Applications.
Manipulating Data in PL/SQL. 2 home back first prev next last What Will I Learn? Construct and execute PL/SQL statements that manipulate data with DML.
8 Copyright © 2005, Oracle. All rights reserved. Managing Data.
Transactions and Locks A Quick Reference and Summary BIT 275.
7 Copyright © 2005, Oracle. All rights reserved. Managing Undo Data.
Database structure and space Management. Segments The level of logical database storage above an extent is called a segment. A segment is a set of extents.
8 Copyright © Oracle Corporation, All rights reserved. Manipulating Data.
Random Logic l Forum.NET l Transaction Isolation Levels Forum.NET Meeting ● Nov
9 Manipulating Data. 9-2 Objectives At the end of this lesson, you should be able to: Describe each DML statement Insert rows into a table Update rows.
CSC 411/511: DBMS Design Dr. Nan WangCSC411_L12_JDBC_MySQL 1 Transations.
Transactions, Roles & Privileges Oracle and ANSI Standard SQL Lecture 11.
A Guide to SQL, Eighth Edition Chapter Six Updating Data.
Module 11: Managing Transactions and Locks
Database Systems: Design, Implementation, and Management Eighth Edition Chapter 10 Transaction Management and Concurrency Control.
©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.
7 Copyright © Oracle Corporation, All rights reserved. Instance and Media Recovery Structures.
1 Copyright © 2009, Oracle. All rights reserved. Controlling User Access.
Module 14: Managing Transactions and Locks. Overview Introducing Transactions and Locks Managing Transactions Understanding SQL Server Locking Architecture.
מימוש מערכות מסדי נתונים (236510) Lecture 2 & 3 : Oracle 12c Database SQL Server Data Concurrency : Transactions and Locking B+ Trees By David Itshak
6 Copyright © Oracle Corporation, All rights reserved. Backup and Recovery Overview.
In this session, you will learn to: Implement triggers Implement transactions Objectives.
Chapter 13 Managing Transactions and Concurrency Database Principles: Fundamentals of Design, Implementation, and Management Tenth Edition.
Locks, Blocks & Isolation Oh My!. About Me Keith Tate Data Professional for over 14 Years MCITP in both DBA and Dev tracks
4 Copyright © 2004, Oracle. All rights reserved. Managing the Oracle Instance.
Oracle 11g: SQL Chapter 5 Data Manipulation and Transaction Control.
6 Copyright © 2009, Oracle. All rights reserved. Using Dynamic SQL.
1 Copyright © 2005, Oracle. All rights reserved. Oracle Database Administration: Overview.
2 Copyright © 2009, Oracle. All rights reserved. Managing Schema Objects.
9 Copyright © 2005, Oracle. All rights reserved. Managing Undo Data.
10 Copyright © 2007, Oracle. All rights reserved. Managing Undo Data.
Managing Data and Concurrency
LAB: Web-scale Data Management on a Cloud
Essbase Data Integrity
Chapter 10 Transaction Management and Concurrency Control
1 Manipulating Data. 2 Objectives After completing this lesson, you should be able to do the following:  Describe each data manipulation language (DML)
Introduction of Week 13 Return assignment 11-1 and 3-1-5
Module 13: Creating Highly Concurrent SQL Server 2012 Applications
Presentation transcript:

9 Copyright © 2009, Oracle. All rights reserved. Managing Data Concurrency

Copyright © 2009, Oracle. All rights reserved Objectives After completing this lesson, you should be able to: Describe the locking mechanism and how Oracle manages data concurrency Monitor and resolve locking conflicts

Copyright © 2009, Oracle. All rights reserved Locks Prevent multiple sessions from changing the same data at the same time Are automatically obtained at the lowest possible level for a given statement Do not escalate Transaction 1 SQL> UPDATE employees 2 SET salary=salary*1.1 3 WHERE employee_id=100; SQL> UPDATE employees 2 SET salary=salary WHERE employee_id=100; Transaction 2

Copyright © 2009, Oracle. All rights reserved Locking Mechanism High level of data concurrency: –Row-level locks for inserts, updates, and deletes –No locks required for queries Automatic queue management Locks held until the transaction ends (with the COMMIT or ROLLBACK operation) Transaction 1 SQL> UPDATE employees 2 SET salary=salary*1.1 3 WHERE employee_id=101; SQL> UPDATE employees 2 SET salary=salary WHERE employee_id=100; Transaction 2 Example Assume that the rows for employee_id 100 and 101 reside in the same block:

Copyright © 2009, Oracle. All rights reserved Data Concurrency Time: 09:00:00 Transaction 1 UPDATE hr.employees SET salary=salary+100 WHERE employee_id=100; Transaction 2 UPDATE hr.employees SET salary=salary+100 WHERE employee_id=101; Transaction 3 UPDATE hr.employees SET salary=salary+100 WHERE employee_id=102;... Transaction x UPDATE hr.employees SET salary=salary+100 WHERE employee_id=xxx;

Copyright © 2009, Oracle. All rights reserved

Copyright © 2009, Oracle. All rights reserved DML Locks Each DML transaction must acquire two locks: EXCLUSIVE row lock on the row or rows being updated Table lock (TM) in ROW EXCLUSIVE (RX) mode on the table containing the rows SQL> UPDATE employees 2 SET salary=salary*1.1 3 WHERE employee_id= 106; 1 row updated. SQL> UPDATE employees 2 SET salary=salary*1.1 3 WHERE employee_id= 107; 1 row updated. Transaction 2Transaction 1

Copyright © 2009, Oracle. All rights reserved Enqueue Mechanism The enqueue mechanism keeps track of: Sessions waiting for locks Requested lock mode Order in which sessions requested the lock

Copyright © 2009, Oracle. All rights reserved Lock Conflicts UPDATE employees SET salary=salary+100 WHERE employee_id=100; 1 row updated. 9:00:00 UPDATE employees SET salary=salary+100 WHERE employee_id=101; 1 row updated. UPDATE employees SET COMMISION_PCT=2 WHERE employee_id=101; Session waits enqueued due to lock conflict. 9:00:05 SELECT sum(salary) FROM employees; SUM(SALARY) Session still waiting! 16:30:00 Many selects, inserts, updates, and deletes during the last 7.5 hours, but no commits or rollbacks! 1 row updated. Session continues. 16:30:01 commit; Transaction 1Transaction 2Time

Copyright © 2009, Oracle. All rights reserved Possible Causes of Lock Conflicts Uncommitted changes Long-running transactions Unnecessarily high locking levels

Copyright © 2009, Oracle. All rights reserved Detecting Lock Conflicts Select Blocking Sessions on the Performance page. Click the Session ID link to view information about the locking session, including the actual SQL statement.

Copyright © 2009, Oracle. All rights reserved Resolving Lock Conflicts To resolve a lock conflict: Have the session holding the lock commit or roll back Terminate the session holding the lock (in an emergency)

Copyright © 2009, Oracle. All rights reserved Resolving Lock Conflicts with SQL SQL statements can be used to determine the blocking session and kill it. SQL> alter system kill session '144,8982' immediate; SQL> select SID, SERIAL#, USERNAME from V$SESSION where SID in (select BLOCKING_SESSION from V$SESSION) Result: 1 2

Copyright © 2009, Oracle. All rights reserved Deadlocks Transaction 2Transaction 1 UPDATE employees SET salary = salary x 1.1 WHERE employee_id = 1000; UPDATE employees SET salary = salary x 1.1 WHERE employee_id = 2000; ORA-00060: Deadlock detected while waiting for resource UPDATE employees SET manager = 1342 WHERE employee_id = 2000; UPDATE employees SET manager = 1342 WHERE employee_id = 1000; 9:00 9:15 9:16

Copyright © 2009, Oracle. All rights reserved Quiz The lock mechanism defaults to a fine-grained, row-level locking mode. 1.True 2.False

Copyright © 2009, Oracle. All rights reserved Quiz When the deadlock occurs, Oracle database automatically: 1.Waits 300 seconds before terminating both sessions 2.Terminates one statement with an error in one session 3.Terminates the statements with an error in both sessions 4.Takes no action by default and leaves it to DBA

Copyright © 2009, Oracle. All rights reserved Summary In this lesson, you should have learned how to: Describe the locking mechanism and how Oracle manages data concurrency Monitor and resolve locking conflicts

Copyright © 2009, Oracle. All rights reserved Practice 9 Overview: Managing Data and Concurrency This practice covers the following topics: Identifying locking conflicts Resolving locking conflicts