pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: David Johnston <polobo@yahoo.com>
To: 'Pavel Arnošt' <pavel.arnost@loutka.cz>
To: pgsql-jdbc@postgresql.org
Subject: Re: Statement.setQueryTimeout() with autoCommit=false
Date: Thu, 6 Dec 2012 15:55:53 -0500
Message-ID: <016a01cdd3f4$15296dd0$3f7c4970$@yahoo.com> (raw)
In-Reply-To: <a92866a3-fdb4-4a57-b3d0-197515b4d9cc@googlegroups.com>
References: <5097e057-c9b9-42f0-bed0-219eab05bb7d@googlegroups.com>
	<CADK3HHL4G0HCj-v2L-tp2EhqNP=tuuZZqzSTMSCahWbFZdsH5A@mail.gmail.com>
	<50C0E09A.4070408@ttc-cmc.net>
	<014101cdd3e0$a9a302a0$fce907e0$@yahoo.com>
	<CADK3HH+iU09LJRauGunft2YbZ_mbJLyJAzqEfQF2GPuJY3YNWA@mail.gmail.com>
	<a92866a3-fdb4-4a57-b3d0-197515b4d9cc@googlegroups.com>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-jdbc>

The statement timeout that you provided is attached to the INSERT statement
- which executed just fine even though it wasn't comitted.  The exception
you are seeing in the "autoCommit(false)" scenario occurs at "conn.commit()"
which implicitly executes "COMMIT;" on the backend and fails due to the
replication situation.

In "autocommit" mode the commit is executed as part of the same statement as
the INSERT (it is a compound statement I guess) and as such the timeout is
still in effect at that time.

David J.

> -----Original Message-----
> From: pgsql-jdbc-owner@postgresql.org [mailto:pgsql-jdbc-
> owner@postgresql.org] On Behalf Of Pavel Arnošt
> Sent: Thursday, December 06, 2012 3:26 PM
> To: pgsql-jdbc@postgresql.org
> Subject: Re: [JDBC] Statement.setQueryTimeout() with autoCommit=false
> 
> That insert was against PostgreSQL server with synchronous replication and
> dead slave.
> 
> On Thursday, December 6, 2012 9:18:48 PM UTC+1, Dave Cramer wrote:
> > Well my point was that that insert statement shouldn't last long enough
to
> time out ?
> >
> >
> > Dave
> >
> > Dave Cramer
> >
> > dave.cramer(at)credativ(dot)ca
> > http://www.credativ.ca
> >
> >
> >
> >
> >
> >
> >
> > On Thu, Dec 6, 2012 at 1:36 PM, David Johnston <pol...@yahoo.com>
> wrote:
> >
> >
> >
> > > -----Original Message-----
> >
> > > From: pgsql-jd...@postgresql.org [mailto:pgsql-jdbc-
> >
> > > ow...@postgresql.org] On Behalf Of dmp
> >
> > > Sent: Thursday, December 06, 2012 1:15 PM
> >
> > > To: pgsql...@postgresql.org
> >
> > > Cc: pavel....@loutka.cz
> >
> > > Subject: Re: [JDBC] Statement.setQueryTimeout() with
> > > autoCommit=false
> >
> > >
> >
> > > Exactly.
> >
> > >
> >
> > > According to the Java API:
> >
> > >
> >
> > > void setAutoCommit(boolean autoCommit) throws SQLException
> >
> > >
> >
> > >      Sets this connection's auto-commit mode to the given state. If
> > > a
> >
> > > connection is in auto-commit mode, then all its SQL statements will
> > > be
> >
> > > executed and committed as individual transactions. Otherwise, its
> > > SQL
> >
> > > statements are grouped into transactions that are terminated by a
> > > call to
> >
> > > either the method commit or the method rollback. By default, new
> >
> > > connections are in auto-commit mode.
> >
> > >
> >
> > > By setting setAutoCommit(false) you are deciding to tell the
> > > database your
> >
> > > code will determine when to commit the transaction. Thereby I would
> > > say
> >
> > > overiding setQueryTimeout().
> >
> > >
> >
> > > danap.
> >
> >
> >
> > Even within an manually administered transaction the setting of
> >
> > "setQueryTimeout()" will (should?) act on the individual statements
> > that
> >
> > make up the transaction.  If any individual statement within the
> > transaction
> >
> > exceeds the limit that statement will fail and thus put the
> > transaction into
> >
> > a "failed" state where a rollback (possibly to savepoint) is required.
> > The
> >
> > transaction itself does not constitute a statement and as such it can
> > run
> >
> > indefinitely long regardless of the presence of a statement timeout.
> >
> >
> >
> > David J.
> >
> >
> >
> >
> >
> > >
> >
> > > Dave Cramer wrote:
> >
> > > > Why would the query timeout at all ?
> >
> > > >
> >
> > > > The query timeout is for long running queries. If the query takes
> >
> > > > longer than n seconds it will timeout.
> >
> > > >
> >
> > > > Dave
> >
> > > >
> >
> > > > Dave Cramer
> >
> > > >
> >
> > > > dave.cramer(at)credativ(dot)ca
> >
> > > > http://www.credativ.ca
> >
> > > >
> >
> > > >
> >
> > > >
> >
> > > > On Thu, Dec 6, 2012 at 12:04 PM, <pavel....@loutka.cz
> >
> > > > <mailto:pavel....@loutka.cz>> wrote:
> >
> > > >
> >
> > > >     Hi,
> >
> > > >
> >
> > > >     does setQueryTimeout work with autoCommit=false? When
> > > > autoCommit
> >
> > > is
> >
> > > >     true, this code timeouts after 5 seconds (as expected):
> >
> > > >
> >
> > > > ~
> >
> > >  > ~
> >
> > >  > ~
> >
> > > >     --
> >
> > > >
> >
> > > >     But if I set autoCommit to false, this code timeouts after 30
> >
> > > >     seconds on read timeout:
> >
> > > >
> >
> > > >     --
> >
> > > > ~
> >
> > >  > ~
> >
> > >  > ~
> >
> > > >     --
> >
> > > >
> >
> > > >     I'm confused what's setQueryTimeout() method for, why it
> > > > doesn't
> >
> > > >     work with manual transactions?
> >
> > >
> >
> > >
> >
> > > --
> >
> > > Sent via pgsql-jdbc mailing list (pgsql...@postgresql.org) To make
> >
> > changes
> >
> > > to your subscription:
> >
> > > http://www.postgresql.org/mailpref/pgsql-jdbc
> >
> >
> >
> >
> >
> >
> >
> > --
> >
> > Sent via pgsql-jdbc mailing list (pgsql...@postgresql.org)
> >
> > To make changes to your subscription:
> >
> > http://www.postgresql.org/mailpref/pgsql-jdbc
> 
> 
> 
> --
> Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org) To make
changes
> to your subscription:
> http://www.postgresql.org/mailpref/pgsql-jdbc



-- 
Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-jdbc



view thread (14+ messages)  latest in thread

Message-ID: <016a01cdd3f4$15296dd0$3f7c4970$@yahoo.com>
Permalink:  ../016a01cdd3f4$15296dd0$3f7c4970$@yahoo.com/
Also on:    postgresql.org/message-id/016a01cdd3f4$15296dd0$3f7c4970$@yahoo.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: polobo@yahoo.com, pavel.arnost@loutka.cz
  Subject: Re: Statement.setQueryTimeout() with autoCommit=false
  In-Reply-To: <016a01cdd3f4$15296dd0$3f7c4970$@yahoo.com>
  References: <5097e057-c9b9-42f0-bed0-219eab05bb7d@googlegroups.com> <CADK3HHL4G0HCj-v2L-tp2EhqNP=tuuZZqzSTMSCahWbFZdsH5A@mail.gmail.com> <50C0E09A.4070408@ttc-cmc.net> <014101cdd3e0$a9a302a0$fce907e0$@yahoo.com> <CADK3HH+iU09LJRauGunft2YbZ_mbJLyJAzqEfQF2GPuJY3YNWA@mail.gmail.com> <a92866a3-fdb4-4a57-b3d0-197515b4d9cc@googlegroups.com> <016a01cdd3f4$15296dd0$3f7c4970$@yahoo.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