0

I've always thought that READ_COMMITTED (DB2 calls it Cursor Stability (CS)) meant that you do NOT lock on reads, and that you only read the committed data. A situation just came up that makes me realize that DB2 is locking, albeit very briefly, on reads in CS.

Because it's brief, that makes it vulnerable to deadlocking. We have a client code that updated row X, then calls a web service that, among many other things, needs to read row X. Because the client code need to be able to rollback if the web service fails, it must hold that lock during the web service call.

With the service running at READ_COMMITTED, I thought it would not wait for the record, but would just read the old data and continue (which is fine).

Is there a way, short of running in READ_UNCOMMITTED (which gives me the willies) to make my service NOT go into lock-wait on a read event? I am primarily operating theough java & hibernate, but if you know tricks purely from a DB2 side even that would be informative.

Entropy
  • 1,219
  • 6
  • 21
  • 45
  • see http://stackoverflow.com/questions/19629299/ms-sql-server-2008-with-nolock-equivalent-for-ibm-db2-9-7 – dav1dsm1th May 02 '14 at 19:00
  • 3
    Which type of OS is your DB2 server running on, and which version of DB2? – WarrenT May 02 '14 at 19:48
  • What is the webservice doing - could you simply update the database _afterwards_? I believe DB2 is smart enough to share locks during a session. If you have two different systems/session accessing the same row...why? – Clockwork-Muse May 03 '14 at 01:23

1 Answers1

2

The default behaviour in CURSOR STABILITY (the DB2 way), readers are blocked. However, with the new Oracle-like features, this behavior can be changed.

Depending your DB2 version, and if you migrated, probably you simply need to change to the CUR_COMMIT level.

Please take a look at this article, that explains very clearly the behavior.

More information is available in the product documentation.

Clockwork-Muse
  • 12,806
  • 6
  • 31
  • 45
AngocA
  • 7,655
  • 6
  • 39
  • 55