473,394 Members | 1,701 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,394 software developers and data experts.

failed insert because of duplicate rows and still locks held by application

Hi,

we have a contention problem because of an application which tries to
insert a duplicate row in a table with primary key. This insert fails
of course but the locks are not released within this transcation.

Why DB2 does not release the X lock after a failed insert???

We use DB2 UDB EEE Version 7.2 Fixpak 9, but we also can reproduce the
Problem on DB2 UDB ESE 8.1 Linux Fixpak 4.

I can reproduce this behavior with the statements below.

db2 +c insert into testtab values(1)
DB21034E The command was processed as an SQL statement because it was
not a
valid Command Line Processor command. During SQL processing it
returned:
SQL0803N One or more values in the INSERT statement, UPDATE
statement, or
foreign key update caused by a DELETE statement are not valid because
the
primary key, unique constraint or unique index identified by "1"
constrains
table "DB2ADMIN.TESTTAB" from having duplicate rows for those columns.
SQLSTATE=23505

db2 get snapshot for locks for application agentid 3

Application Lock Snapshot

Snapshot timestamp = 22/04/2004
10.53.23.324831

Application handle = 3
Application ID = *LOCAL.DB2.040422084540
Sequence number = 0001
Application name = db2bp.exe
Authorization ID = DB2ADMIN
Application status = UOW Waiting
Status change time = Not Collected
Application code page = 1252
Locks held = 5
Total wait time (ms) = Not Collected

List Of Locks
Lock Object Name = 4
Node number lock is held at = 0
Object Type = Row
Tablespace Name = USERSPACE1
Table Schema = DB2ADMIN
Table Name = TESTTAB
Mode = W
Status = Granted
Lock Escalation = NO

Lock Object Name = 5
Node number lock is held at = 0
Object Type = Row
Tablespace Name = USERSPACE1
Table Schema = DB2ADMIN
Table Name = TESTTAB
Mode = X
Status = Granted
Lock Escalation = NO

Lock Object Name = 22
Node number lock is held at = 0
Object Type = Table
Tablespace Name = USERSPACE1
Table Schema = DB2ADMIN
Table Name = TESTTAB
Mode = IX
Status = Granted
Lock Escalation = NO

Lock Object Name = 0
Node number lock is held at = 0
Object Type = Internal V Lock
Tablespace Name =
Table Schema =
Table Name =
Mode = S
Status = Granted
Lock Escalation = NO

Lock Object Name = 0
Node number lock is held at = 0
Object Type = Internal P Lock
Tablespace Name =
Table Schema =
Table Name =
Mode = S
Status = Granted
Lock Escalation = NO

Thanks, Florian
Nov 12 '05 #1
10 5089
I doubt DB2 releases a (row) lock on statement failure.
You need to rollback or commit.

Cheers
Serge
--
Serge Rielau
DB2 SQL Compiler Development
IBM Toronto Lab
Nov 12 '05 #2
I doubt DB2 releases a (row) lock on statement failure.
You need to rollback or commit.

Cheers
Serge
--
Serge Rielau
DB2 SQL Compiler Development
IBM Toronto Lab
Nov 12 '05 #3

"florian" <au*****@web.de> wrote in message
news:35*************************@posting.google.co m...
Hi,

we have a contention problem because of an application which tries to
insert a duplicate row in a table with primary key. This insert fails
of course but the locks are not released within this transcation.

Why DB2 does not release the X lock after a failed insert???

We use DB2 UDB EEE Version 7.2 Fixpak 9, but we also can reproduce the
Problem on DB2 UDB ESE 8.1 Linux Fixpak 4.

I can reproduce this behavior with the statements below.

db2 +c insert into testtab values(1)


When you use +c you are turning off auto-commit so you need to do an
explicit commit to release the lock(s).
Nov 12 '05 #4

"florian" <au*****@web.de> wrote in message
news:35*************************@posting.google.co m...
Hi,

we have a contention problem because of an application which tries to
insert a duplicate row in a table with primary key. This insert fails
of course but the locks are not released within this transcation.

Why DB2 does not release the X lock after a failed insert???

We use DB2 UDB EEE Version 7.2 Fixpak 9, but we also can reproduce the
Problem on DB2 UDB ESE 8.1 Linux Fixpak 4.

I can reproduce this behavior with the statements below.

db2 +c insert into testtab values(1)


When you use +c you are turning off auto-commit so you need to do an
explicit commit to release the lock(s).
Nov 12 '05 #5
That's the point. Of course DB2 does release the lock when i do
commit/rollback. My question is: why DB2 generates that lock even if
the insert fails?

cheers
Florian

"Mark A" <ma@switchboard.net> wrote in message news:<Zs**************@news.uswest.net>...
When you use +c you are turning off auto-commit so you need to do an
explicit commit to release the lock(s).

Nov 12 '05 #6
That's the point. Of course DB2 does release the lock when i do
commit/rollback. My question is: why DB2 generates that lock even if
the insert fails?

cheers
Florian

"Mark A" <ma@switchboard.net> wrote in message news:<Zs**************@news.uswest.net>...
When you use +c you are turning off auto-commit so you need to do an
explicit commit to release the lock(s).

Nov 12 '05 #7
> "Mark A" <ma@switchboard.net> wrote in message
news:<Zs**************@news.uswest.net>...
When you use +c you are turning off auto-commit so you need to do an
explicit commit to release the lock(s)."florian" <au*****@web.de> wrote
in message news:35*************************@posting.google.co m... That's the point. Of course DB2 does release the lock when i do
commit/rollback. My question is: why DB2 generates that lock even if
the insert fails?

cheers
Florian

DB2 obtains the lock before it knows whether the insert will fail or be
successful. If DB2 did not obtain the lock beforehand, the lock would be
useless.
Nov 12 '05 #8
> "Mark A" <ma@switchboard.net> wrote in message
news:<Zs**************@news.uswest.net>...
When you use +c you are turning off auto-commit so you need to do an
explicit commit to release the lock(s)."florian" <au*****@web.de> wrote
in message news:35*************************@posting.google.co m... That's the point. Of course DB2 does release the lock when i do
commit/rollback. My question is: why DB2 generates that lock even if
the insert fails?

cheers
Florian

DB2 obtains the lock before it knows whether the insert will fail or be
successful. If DB2 did not obtain the lock beforehand, the lock would be
useless.
Nov 12 '05 #9
>
DB2 obtains the lock before it knows whether the insert will fail or be
successful. If DB2 did not obtain the lock beforehand, the lock would be
useless.


Ok, you are right, after thinking it over it makes sense and my
question was kind of stupid.

Thank you
Florian
Nov 12 '05 #10
>
DB2 obtains the lock before it knows whether the insert will fail or be
successful. If DB2 did not obtain the lock beforehand, the lock would be
useless.


Ok, you are right, after thinking it over it makes sense and my
question was kind of stupid.

Thank you
Florian
Nov 12 '05 #11

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

Similar topics

8
by: Kragen Sitaker | last post by:
ERROR: Cannot insert a duplicate key into unique index pg_class_relname_nsp_index We've been getting this error in our application every once in a while --- typically once an hour to once a day,...
0
by: florian | last post by:
Hi, we have a contention problem because of an application which tries to insert a duplicate row in a table with primary key. This insert fails of course but the locks are not released within...
16
by: robert | last post by:
been ruminating on the question (mostly in a 390/v7 context) of whether, and if so when, a row update becomes an insert/delete. i assume that there is a threshold on the number of columns of the...
3
by: Ray | last post by:
I am having my first experience using BLOB as a row in a table. I am using it to insert graphics for labels we print. I have no problem inserting into and select from the table. The graphic is...
3
by: bughunter | last post by:
Description The maximum number of locks held during this transaction. It's not true. :-( When I tried found longest transactions I see next picture: uow_start_time T1, uow_stop T2,...
1
by: shenanwei | last post by:
I have db2 v8.2.5 on AIX V5.3 with all the switches on Buffer pool (DFT_MON_BUFPOOL) = ON Lock (DFT_MON_LOCK) = ON Sort ...
8
by: nano2k | last post by:
Hi Shortly, I keep invoices in a table. Occasionally, someone will fire the execution of a stored procedure (SP) that performs several UPDATEs against (potentially) all invoices OLDER than a...
2
by: nano | last post by:
Does sql server have a way to handle errors in a sproc which would allow one to insert rows, ignoring rows which would create a duplicate key violation? I know if one loops one can handle the error...
5
by: sticky | last post by:
Hi I need to be able to lock a table against INSERT and UPDATE, but not SELECT, for the duration of a transaction. The transaction will be defined at the application level in c#, and then use...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.