Results 1 to 3 of 3
  1. #1
    Join Date
    Nov 2004

    Unanswered: locking- practical application Question!

    hey all!

    I have two applications. Application 1) Being tested and Application 2) helping testing it.

    i am building APPLICATION 2 which i want to intentionally lock a database row. What actually constitiutes locking a row. Does a simple repetitive select of the same row lock the row???? if not then how can i successfully lock the row so that my actual application (APPLICATION 1) which is in test will try and timeout!

  2. #2
    Join Date
    May 2003
    DB2 uses "pessimistic" locking, which means it locks automatically based on the SQL statement (select, insert, update, delete), so there is no command to explicitly lock a row. You can issue a lock table SQL statement (in share mode or exclusive mode).

    There are different kinds of locks, such as share (S) locks and exclusive (X) locks (and other kinds). Share locks are compatible with each other, so multiple share locks can be on the same row without a problem. But X locks do not allow other X locks or any S locks.

    Locks are always released when a commit happens, but a share lock may be released sooner depending on the isolation level. Isolation level determines how long a share lock is held. With CS, the row is only locked while the cursor is on that particular row. With RR, the share lock is held until a commit is issued. All X locks are held until a commit is issued. Refer to the Administration Guide: Performance for details on locks and isolation level.
    M. A. Feldman
    IBM Certified DBA on DB2 for Linux, UNIX, and Windows
    IBM Certified DBA on DB2 for z/OS and OS/390

  3. #3
    Join Date
    May 2002

    select for update !!

    you can use select for update which will make a lock on the row selected.
    let me know if i am wrong .

    Hope it helps

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts