X-Original-To: pgsql-jdbc-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 6B0CB53E93 for ; Thu, 28 Apr 2005 07:30:22 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 63091-10 for ; Thu, 28 Apr 2005 10:30:20 +0000 (GMT) Received: from mail.logix-tt.com (wallaby.dingens.org [212.75.36.180]) by svr1.postgresql.org (Postfix) with ESMTP id C630753E00 for ; Thu, 28 Apr 2005 07:30:18 -0300 (ADT) Received: from kingfisher.intern.logi-track.com (J3980.j.pppool.de [85.74.57.128]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.logix-tt.com (Postfix) with ESMTP id 13C87A86BF; Thu, 28 Apr 2005 12:30:21 +0200 (CEST) Received: from [127.0.0.1] (localhost [127.0.0.1]) by kingfisher.intern.logi-track.com (Postfix) with ESMTP id CF291AAFE5; Thu, 28 Apr 2005 12:28:48 +0200 (CEST) Message-ID: <4270BAE0.1020402@logix-tt.com> Date: Thu, 28 Apr 2005 12:28:48 +0200 From: Markus Schaber Organization: Logical Tracking and Tracing International AG, Switzerland User-Agent: Mozilla Thunderbird 1.0 (X11/20050116) X-Accept-Language: de-DE, de, en-us, en MIME-Version: 1.0 To: "pgsql-jdbc@postgresql.org" Subject: Statement Timeout and Locking X-Enigmail-Version: 0.90.1.0 X-Enigmail-Supports: pgp-inline, pgp-mime Content-Type: multipart/mixed; boundary="------------000403030101000108000204" X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.293 tagged_above=0 required=5 tests=AWL, FORGED_RCVD_HELO, TO_ADDRESS_EQ_REAL X-Spam-Level: X-Archive-Number: 200504/192 X-Sequence-Number: 12799 This is a multi-part message in MIME format. --------------000403030101000108000204 Content-Type: text/plain; charset=ISO-8859-15 Content-Transfer-Encoding: 7bit Hello, In one of our maintainance apps that shuffles some data across independent databases, we need to enshure data consistency, and decided to do this by acquiring a lock in the target database. Now we do not want the application to wait indefinitely for this lock, but fail and complain loudly whenever locking fails. When using the SQL statement SET statement_timeout TO 5000; LOCK TABLE exampletable IN EXCLUSIVE MODE; SET statement_timeout TO DEFAULT; in psql, everything works fine. If someone else has the lock, it aborts with ERROR: canceling query due to user request after waiting 5 seconds. However, the attached java file shows a different behaviour, it seems to wait forever (at least it waited three minutes, and I'll keep it running over lunch). I use PostgreSQL 8.0 JDBC3 with SSL (build 311) and a debian PostgreSQL 7.4.7-5 server. Does someone have an explanation for this, or even better, a fix or workaround? Markus --------------000403030101000108000204 Content-Type: text/x-java; name="LockTest.java" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="LockTest.java" import java.sql.Connection; import java.sql.DriverManager; public class LockTest { public static void main(String[] args) throws Exception { System.out.println("using: "+org.postgresql.Driver.getVersion()); Connection conn = DriverManager.getConnection("jdbc:postgresql://localhost:5432/locktest", "test", "blubb"); conn.setAutoCommit(false); conn.setTransactionIsolation(Connection.TRANSACTION_SERIALIZABLE); conn.setReadOnly(false); conn.createStatement().execute("SET statement_timeout TO 5000; LOCK TABLE exampletable IN EXCLUSIVE MODE; SET statement_timeout TO DEFAULT;"); System.out.println("Lock acquired"); Thread.sleep(10000000); } } --------------000403030101000108000204--