1. Trang chủ
  2. » Công Nghệ Thông Tin

Monitoring and Detecting Lock Contention pdf

19 196 0
Tài liệu đã được kiểm tra trùng lặp

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 19
Dung lượng 242 KB

Các công cụ chuyển đổi và chỉnh sửa cho tài liệu này

Nội dung

After completing this lesson, you should be able to do the following: • Define levels of locking • Identify causes of contention • Prevent locking problems • Use Oracle utilities to dete

Trang 1

Copyright © Oracle Corporation, 2002 All rights reserved.

Monitoring and Detecting

Lock Contention

Trang 2

After completing this lesson, you should be able to do the following:

Define levels of locking

Identify causes of contention

Prevent locking problems

Use Oracle utilities to detect lock contention

Resolve contention in an emergency

Resolve deadlock conditions

Trang 3

17-3 Copyright © Oracle Corporation, 2002 All rights reserved.

Locking Mechanism

Automatic management

High level of data concurrency

Row-level locks for DML transactionsNo locks required for queries

Multi-version consistency

Exclusive and Share lock modes

Locks held until commit or rollback operations

are performed

Trang 4

Data Concurrency

Transaction 1

SQL> SELECT salary

2 FROM employees

3 WHERE id = 10;

SALARY 1000

SQL> UPDATE employees

2 SET salary=salary*1.1

3 WHERE id= 24878;

1 row updated.

SQL> UPDATE employees

2 SET salary=salary+1200;

13120 rows updated.

SQL> UPDATE employees

2 SET salary=salary*1.1

3 WHERE id= 24877;

1 row updated.

Transaction 2

Trang 5

17-6 Copyright © Oracle Corporation, 2002 All rights reserved.

Two Types of Locks

DML or data locks:

Table-level locksRow-level locks

DDL or dictionary locks

(TM)

(TX)

Trang 6

DML Locks

A DML transaction gets at least two locks:

A shared table lock

An exclusive row lock

Trang 7

17-9 Copyright © Oracle Corporation, 2002 All rights reserved.

Enqueue Mechanism

The enqueue mechanism keeps track of:

Users waiting for locks

The requested lock mode

The order in which users requested the lock

Trang 8

Table Lock Modes

These table lock modes are automatically assigned

by the Oracle server:

Row Exclusive (RX): INSERT, UPDATE, DELETE

Row Share (RS): SELECT FOR UPDATE

Trang 9

17-12 Copyright © Oracle Corporation, 2002 All rights reserved.

Manually Locking a Table

Manually acquired in LOCK TABLE statement:

Share (S)

No DML operations allowedImplicitly used for referential integrity

SQL> LOCK TABLE hr.employees IN share MODE;

Trang 10

Manually Locking a Table

Share Row Exclusive (SRX)

No DML operations or Share mode allowedImplicitly used for referential integrity

No index is required on the foreign key column in

the child table

Exclusive (X)

No DML or DDL operations allowed by other sessions

No manual locks allowed by other sessionsQueries are allowed

Trang 11

17-14 Copyright © Oracle Corporation, 2002 All rights reserved.

DML Locks in Blocks

Row 6 Block Header

Lock bytes

Row 1

1

2

TX slot 1 TX slot 2

Trang 12

DDL Locks

Exclusive DDL locks are required for:

DROP TABLE statements

ALTER TABLE statements

(The lock is released when the DDL statement

completes.)

Shared DDL locks are required for:

CREATE PROCEDURE statements

AUDIT statements

(The lock is released when the DDL parse

Trang 13

17-17 Copyright © Oracle Corporation, 2002 All rights reserved.

Possible Causes of Lock Contention

Unnecessarily high locking levels

Long-running transactions

Uncommitted changes

Other products imposing higher-level locks

Trang 14

Diagnostic Tools for Monitoring

Locking Activity

Transaction 1

UPDATE employees

SET salary =

salary x 1.1;

Transaction 2 Transaction 3

v$lock

v$locked_object

UPDATE employees SET salary =

salary x 1.1 WHERE empno = 1000; UPDATE employees

SET salary = salary x 1.1

Trang 15

17-20 Copyright © Oracle Corporation, 2002 All rights reserved.

Transaction 1

Guidelines for Resolving Contention

UPDATE employees SET salary = salary x 1.1 WHERE empno = 1000;

> COMMIT/ROLLBACK ;

UPDATE employees SET salary = salary x 1.1 WHERE empno = 1000;

1 row updated;

Transaction 2

> ALTER SYSTEM KILL SESSION ‘10,23’;

9:00

9:05 10:30 11:30

Trang 16

Performance Manager: Locks

Trang 17

17-23 Copyright © Oracle Corporation, 2002 All rights reserved.

Transaction

2

Transaction

1

Deadlocks

UPDATE employees

SET salary = salary x 1.1

WHERE empno = = 1000;

UPDATE employees

SET salary = salary x 1.1

WHERE empno = 2000;

ORA-00060:

Deadlock detected while

waiting for resource

UPDATE employees SET manager = 1342 WHERE empno = 2000; UPDATE employees SET manager = 1342 WHERE empno = 1000;

9:00

9:15

9:16

Trang 18

ORA-00060:

Deadlock detected while waiting for resource

Trace file

Server process

SID_ora_PID.trc

UNIX

Trang 19

17-26 Copyright © Oracle Corporation, 2002 All rights reserved.

Summary

In this lesson, you should have learned to do the following:

Define levels of locking

Identify causes of contention

Prevent locking problems

Use Oracle utilities to detect lock contention

Resolve contention in an emergency

Resolve deadlock conditions

Ngày đăng: 15/03/2014, 17:20

TỪ KHÓA LIÊN QUAN

🧩 Sản phẩm bạn có thể quan tâm