pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Markus Schaber <schabi@logix-tt.com>
To: pgsql-jdbc@postgresql.org <pgsql-jdbc@postgresql.org>
Subject: Statement Timeout and Locking
Date: Thu, 28 Apr 2005 12:28:48 +0200
Message-ID: <4270BAE0.1020402@logix-tt.com> (raw)

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

Attachments:

LockTest.java (text/x-java, 718B) download 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); } }

view thread (6+ messages)  latest in thread

Message-ID: <4270BAE0.1020402@logix-tt.com>
Permalink:  ../4270BAE0.1020402@logix-tt.com/
Also on:    postgresql.org/message-id/4270BAE0.1020402@logix-tt.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-jdbc@postgresql.org
  Cc: schabi@logix-tt.com
  Subject: Re: Statement Timeout and Locking
  In-Reply-To: <4270BAE0.1020402@logix-tt.com>
  References: <4270BAE0.1020402@logix-tt.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox