* DB2 uses locks to control concurrence and prevent lost updates.
* Locks prevent one program from accessing data that another program has changed but not yet committed.
* DB2 acquires all locks implicitly under DB2 control.
Lock can be obtained ==>
* Implicitly - by the system
* Explicitly - by the user
There are 2 kinds of locks :
Shared S
Exclusive X
SHARE MODE Lock :
* Is used for querying consistent data
* Prevents other users from updating data, you are reading
* Prevents other users from putting EXCLUSIVE mode lock on the table
* Lets other users read the data
* Locks the whole table
Example :
LOCK TABLE EMPLOYEE
IN SHARE MODE ;
EXCLUSIVE MODE lock :
* Is used for changing data
* Prevents other users from updating data, you’re reading
* Prevents other users from putting ANY lock on the table
* Lets other users read the data
* Does not guarantee current data
* Locks the whole table
Example :
LOCK TABLE EMPLOYEE IN EXCLUSIVE MODE ;
Locks can be obtained implicitly or explicitly.
Implicit lock is issued by the system itself.
DB2 provides facilities for explicit locking :
* The SQL statement LOCK TABLE
* The ISOLATION parameter on the BIND command
* The tablespace LOCKSIZE parameter
* The ACQUIRE/RELEASE parameters on the BIND command
No comments:
Post a Comment