Results 1 to 3 of 3
  1. #1
    Join Date
    Mar 2003
    Posts
    4

    Answered: LOCK table in SHARE mode does not block client

    Hi,

    Based on the documentation at https://www-01.ibm.com/support/knowl...locktable.dita
    a SHARE MODE lock prevents other processes from executing anything but read-only operations on the table.

    We tried the following:
    Process 1(P1) : LOCK table T1 in SHARE MODE.
    P2: LOCK table T1 in SHARE MODE.

    We were expecting P2 to be held up for the lock to be released as P1 had aquired the lock first. Instead, the statement succeeds for P2.

    Does this not conflict with the statement in the documentation?

    We have two identical programs P1 and P2 and want to ensure that only one of them gets a chance to INSERT records in the table at a time. We want each process to :
    Lock the table in share mode
    Insert records
    Commit

    Is there any other way to achieve this?

    Regards,
    Yash

  2. Best Answer
    Posted by ARWinner

    "Share locks do not prevent other share locks. These are the locks that DB2 will use internally when performing reads. If you really need to prevent another application from accessing the table while another one is inserting, then you need to use EXCLUSIVE locks. You should keep you units of work really short when doing this, as it prevents all access to the table.

    Andy"


  3. #2
    Join Date
    Jan 2003
    Posts
    4,292
    Provided Answers: 5
    Share locks do not prevent other share locks. These are the locks that DB2 will use internally when performing reads. If you really need to prevent another application from accessing the table while another one is inserting, then you need to use EXCLUSIVE locks. You should keep you units of work really short when doing this, as it prevents all access to the table.

    Andy

  4. #3
    Join Date
    Dec 2007
    Location
    Richmond, VA
    Posts
    1,328
    Provided Answers: 5
    and a quick piece of advice. Don't put roadblocks into your application. Really consider what you are doing and why. A database and computing processes are set up and allow for multiple processes accessing it simultaneously for a reason.
    Dave

Tags for this Thread

Posting Permissions

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