Understand database lock concept

Database lock concept use when many user want to concurrently access in the database such as oracle database. When many user want to write the same data at a time, the data must be destroyed. To handle this problem we use locks. The data can be locked in two modes
1. Shared(S) mode: The data item can only be read. S lock is requested using lock-S instruction.
2. Exclusive(X) mode:The data item can be both read as well as written. X-lock is requested using lock-X instruction.

The concurrency control manager handle the lock request. If you want to lock any data item, at first you need to make a request to the concurrency control manager. The concurrency control manager check it and give you the response is the transaction grant or not. When you lock a data item in share mode, another share mode can be able to lock it but when you lock it in Exclusive mode, another mode cannot lock the data at this time. To handle this compatibility database control manager use lock-compatibility matrix comparison. It shows below:
lock_compatibility_matrix
In this picture S is shared mode and X is exclusive mode. When one share mode lock the data item and another share mode capable of lock that item. Shared mode is compatible with shared mode, but not with
exclusive mode. At any time several shared mode locks can be held simultaneously on a particular data item. A subsequent exclusive mode lock request has to wait until the currently held shared or exclusive mode locks are released.

Comments

Popular posts from this blog

How to show only month and year fields in android Date-picker?

How to construct a B+ tree with example

Conflict Serializability in database