473,322 Members | 1,501 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

why it is exclusive lock

hi, i am using db2 udb v8.1 on windows, i create a index on a unique
value column on a table to try to create row lock, here is what i do ,

sql = select value from table where id=1 for update, the auto commit
is true. if the table has more than one row, i got row U lock, but if
the table has only one row , i get row X lock, is this right, why is
that? i would like this only create row U lock, not row X lock. thanks
for advice
Nov 12 '05 #1
5 7902
"xixi" <da****@yahoo.com> wrote in message
news:c0**************************@posting.google.c om...
hi, i am using db2 udb v8.1 on windows, i create a index on a unique
value column on a table to try to create row lock, here is what i do ,

sql = select value from table where id=1 for update, the auto commit
is true. if the table has more than one row, i got row U lock, but if
the table has only one row , i get row X lock, is this right, why is
that? i would like this only create row U lock, not row X lock. thanks
for advice


Even when a U lock occurs for rows to be updated, an X lock is taken when
the specific row is actually updated.

I don't know if you are confusing an X lock with a table lock. An X lock is
an exclusive lock, either at the row or table level, depending on the
locksize. Locksize depends on whether lock escalation has occurred, or
whether a lock table SQL statement has been issued, or whether the table has
been altered to set the locksize.
Nov 12 '05 #2
i found more info, when there is only row in the table and auto
commit is true, select ... for update only create a row U lock and
table IX lock, then when try to do update sql …on this row , after
statement.execute(sql), the row U lock becomes a row X lock, but this
doesn't happen to the table with more than one records. e.g. table 2
has 10 records, same kine of index created, auto commit is true,
update sql won't escalate the row U lock to row X lock. please advise.
this is a strange behavior i didn't know from DB2, does the table size
matter as regards to row lock?
Nov 12 '05 #3
"xixi" <da****@yahoo.com> wrote in message
news:c0**************************@posting.google.c om...
i found more info, when there is only row in the table and auto
commit is true, select ... for update only create a row U lock and
table IX lock, then when try to do update sql .on this row , after
statement.execute(sql), the row U lock becomes a row X lock, but this
doesn't happen to the table with more than one records. e.g. table 2
has 10 records, same kine of index created, auto commit is true,
update sql won't escalate the row U lock to row X lock. please advise.
this is a strange behavior i didn't know from DB2, does the table size
matter as regards to row lock?


I don't understand your concern. The locks are at the row level, even the X
lock is at the row level, so there should be no problem. According to the
documentation, the U lock is converted to a X lock when the row is updated,
but you just don't see it happen.
Nov 12 '05 #4
my concern is the behavior of DB2 is different on different size of
table, if i have only one row in the table, and while this row being
updated, simply after stm.executeUpdate(sql), the row U lock becomes X
lock, instead of release the lock, i have to do cursor.close() (cursor
is the resultset which create the row U lock ) and connection.commit()
to release the X lock (even auto commit is true) , but if the table
has more than one row, after stm.executeUpdate(sql) will release the
row U lock right away, so that is the problem i try to understand.
Nov 12 '05 #5

"xixi" <da****@yahoo.com> wrote in message
news:c0**************************@posting.google.c om...
my concern is the behavior of DB2 is different on different size of
table, if i have only one row in the table, and while this row being
updated, simply after stm.executeUpdate(sql), the row U lock becomes X
lock, instead of release the lock, i have to do cursor.close() (cursor
is the resultset which create the row U lock ) and connection.commit()
to release the X lock (even auto commit is true) , but if the table
has more than one row, after stm.executeUpdate(sql) will release the
row U lock right away, so that is the problem i try to understand.


If you're using Perl DBI or CLI to access the database, your cursor is
probably being created implicitly using the WITH HOLD option. This means
that the locks are released when you close the cursor, instead of when you
commit.

You will want to look at the CURSORHOLD configuration option, described
here:
http://publib.boulder.ibm.com/infoce...d/r0008781.htm

The locking characteristics of DB2 also change depending on your isolation
level, especially with cursors. CS isolation is the default when using Perl
DBI or CLI.

You can read more about isolation levels here:
http://publib.boulder.ibm.com/infoce...n/c0004121.htm

--
Matt Emmerton
DB2 OLTP Performance
IBM Toronto Lab
Nov 12 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Dave Reid | last post by:
Hi everyone... I'm trying to open a text file in exclusive mode (meaning I want to lock out any other processes from accessing the file while I'm working with it). Here's my code: ifstream...
3
by: Uwe C. Schroeder | last post by:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hi. I have the following little stored proc: CREATE OR REPLACE FUNCTION public.ib_nextval(varchar) RETURNS varchar AS 'DECLARE
9
by: Lara | last post by:
Hello freaks, we have many problems with our online reorg and no idea how to resolve it. We had to do an online reorg beacause of 24 h online business. We start the reorg-statements (table by...
2
by: Javier Gomez | last post by:
How to open a linked table in exclusive mode from a FORM in DAO ??? (but,...... please I need it in DAO.) Thank you ! Javier Gomez
1
by: Tim Smith | last post by:
Hi, I am so far familiar with the C# lock keyword, which I understand prevents any other thread from entering the portion of code which is locked, assuming you are locking the same object...
1
by: David C | last post by:
I have a desktop application which uses AxPdf to view PDF file. axPdf.LoadFile("myFile.PDF"); Without going into much detail, I need to make sure that only one person has a given file in the...
17
by: teddysnips | last post by:
One of my clients has asked me to make a change to one of their Access applications. The application is a Front End/Back End standard app. I didn't develop it, but looking at it tells me that...
5
by: =?Utf-8?B?U3BlZWR5?= | last post by:
Sorry for aksing such a basic question but I have searched the internet high and low and none of the solutions seem to help. Here is my (not working) code: FileStream fs = new...
3
by: Arun Srinivasan | last post by:
Please correct me if I am wrong 1. no 2 processes can have exclusive lock on same object (by object, same row or same table) 2. on deadlock incident between 2 processes only one of them will be...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.