简体   繁体   English

具有DB2表锁定的事务性Web应用程序

[英]Transactional Web Application with DB2 Table Locking

We have a Java web application where, at install time, a DBMS is chosen to store the application's data. 我们有一个Java Web应用程序,在安装时将选择一个DBMS来存储应用程序的数据。 We have about 8 choices with MS SQL Server, Oracle, MySQL and PostgreSQL being the most popular with our clients. 我们有大约8种选择,其中MS SQL Server,Oracle,MySQL和PostgreSQL在客户中最受欢迎。 We obviously interface with these databases using JDBC. 我们显然使用JDBC与这些数据库进行交互。 The majority of the DB calls are just SQL within a transaction, very occasionally we'll use database sequences, or a stored procedure if sequences aren't available in the selected DB. 大多数DB调用只是事务中的SQL,偶尔会使用数据库序列,或者如果所选DB中没有可用的序列,则使用存储过程。 The SQL used is very basic and runs on all supported databases without modification or DB specific syntax. 所使用的SQL非常基础,并且可以在所有受支持的数据库上运行,而无需进行修改或特定于DB的语法。

DB2 is an install option, but we seem to have problems with tables locking and pausing transactions, especially with concurrent users that are reading or writing from the same tables simultaneously. DB2是一个安装选项,但是我们似乎在表锁定和暂停事务方面存在问题,尤其是对于同时从同一表读取或写入的并发用户而言。 Maybe I should call these locks Deadlocks, because they will halt all the transactions where the same table is in use. 也许我应该将这些锁称为死锁,因为它们将停止使用同一表的所有事务。 By default we use a transaction isolation level of READ_COMMITTED, to enforce transaction integrity. 默认情况下,我们使用事务隔离级别READ_COMMITTED来增强事务完整性。 Changing this to READ_UNCOMMITTED gets rid of the locks but it is obviously not a good way to run transactions. 将其更改为READ_UNCOMMITTED可以摆脱锁定,但这显然不是运行事务的好方法。

All of our existing code "just works" with MySQL, PostgreSQL and Oracle. 我们所有现有的代码都可以在MySQL,PostgreSQL和Oracle上“正常工作”。 In SQL Server we enable SNAPSHOT ISOLATION on the database and don't have any problems deadlocks at the database level. 在SQL Server中,我们在数据库上启用了SNAPSHOT ISOLATION,并且在数据库级别没有任何死锁问题。

We are currently testing on DB2 9.1 and are seeing these deadlocks occurring. 我们目前正在DB2 9.1上进行测试,并且看到了这些死锁的发生。 The DBMS has been installed with default options. 已使用默认选项安装了DBMS。

I have very little experience with DB2 and am not aware of any options that might remedy these locks, or if this is just how DB2 works. 我对DB2的经验很少,并且不知道可以补救这些锁的任何选项,或者这是否就是DB2的工作方式。

Is there something simple that can make this work without having to synchonize code so that database tables are not accessed simultaneously. 是否有一些简单的方法可以使此工作而不必同步代码,从而不会同时访问数据库表。 I also don't want to modify SQL to contain DB2 specific locking syntax. 我也不想修改SQL以包含特定于DB2的锁定语法。 I won't rule out a problem with our code, but everything seems to work as expected on other DBMS. 我不会排除我们的代码有问题,但是其他DBMS上的一切似乎都可以正常工作。

Any ideas or recommendations? 有什么想法或建议吗?

DB2 locking mechanism works a bit differently than in other databases you are mentioning, which often exposes some lazy programming practices -- I mean no offence, it's just a fact of life. DB2锁定机制的工作方式与您提到的其他数据库略有不同,这通常会暴露一些懒惰的编程实践-我的意思是,没有违法行为,这只是事实。 By the way, what you see are not deadlocks -- these are lock waits. 顺便说一句,您看到的不是死锁-这些是锁等待。

In DB2 locking issues are most commonly resolved by reducing the size of transactions (committing more frequently, processing fewer rows in each transaction) and proper indexing. 在DB2中,锁定问题通常通过减小事务的大小(更频繁地提交,在每个事务中处理更少的行)和适当的索引来解决。

Beginning with DB2 9.7, you have an option of enabling the "currently committed" semantics , which makes DB2 behave more like these other databases in the sense that, instead of waiting for locks on updated rows to be released, queries access previously committed versions of those rows. 从DB2 9.7开始,您可以选择启用“当前提交的”语义 ,这使DB2的行为更像这些其他数据库,在某种意义上,查询无需等待对更新行的锁被释放,而是访问先前提交的版本。这些行。 This approach has its own negative effects though. 但是,这种方法有其自身的负面影响。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM