Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1Tgl7D-0004aB-F5 for pgsql-jdbc@arkaria.postgresql.org; Thu, 06 Dec 2012 23:44:27 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.72) (envelope-from ) id 1Tgl7C-0006ew-3K for pgsql-jdbc@arkaria.postgresql.org; Thu, 06 Dec 2012 23:44:26 +0000 Received: from magus.postgresql.org ([87.238.57.229]) by malur.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1Tgl7A-0006ep-Iz for pgsql-jdbc@postgresql.org; Thu, 06 Dec 2012 23:44:24 +0000 Received: from nm11-vm0.bullet.mail.bf1.yahoo.com ([98.139.213.136]) by magus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1Tgl76-0003f9-EU for pgsql-jdbc@postgresql.org; Thu, 06 Dec 2012 23:44:23 +0000 Received: from [98.139.212.146] by nm11.bullet.mail.bf1.yahoo.com with NNFMP; 06 Dec 2012 23:44:18 -0000 Received: from [76.13.13.47] by tm3.bullet.mail.bf1.yahoo.com with NNFMP; 06 Dec 2012 23:44:18 -0000 Received: from [127.0.0.1] by smtp108.prem.mail.ac4.yahoo.com with NNFMP; 06 Dec 2012 23:44:18 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s1024; t=1354837458; bh=O66IPYtYqgMBohFrTR1ue1LsyelKqTxD+fOAlLVxv2E=; h=X-Yahoo-Newman-Id:X-Yahoo-Newman-Property:X-YMail-OSG:X-Yahoo-SMTP:Received:From:To:References:In-Reply-To:Subject:Date:Message-ID:MIME-Version:Content-Type:Content-Transfer-Encoding:X-Mailer:Thread-Index:Content-Language; b=BJREBnAtE0e9VKPLyiBr9Nkv0No8rC0k5cNgBY8NAsekEgNQgll/fOUoqPFzNwoK3bOzF5z7SjWAVbXDMdJ3WVYN2sjfL6Nhh4JlMizOgaYpBRs/jNh2DoxxPYQc2koCv4Jv8b9WRwhl2ZBrSJdQ0oQ5KMXBwhU+vVTAV8CQ9oE= X-Yahoo-Newman-Id: 581528.41696.bm@smtp108.prem.mail.ac4.yahoo.com X-Yahoo-Newman-Property: ymail-3 X-YMail-OSG: rsTFfSQVM1ldo713OQPf3pqWH2H2R9n4qE8C4K_oMdRfFei KDWOrZOMt9SGSILhI6DeS1Xk7MyWBy2GvaIgdnXdgNCXGFHzlXx7rG.nLroq E4LTm4HGTrarvIFameO.1xGnPMiEiUDCE0Ed8KI2v6EsTwvYT6QeMC5sQbJ1 PZalN2raoMrsteEipxm2Birb8IEq.Q3R0D6Mrn_rBai2CDyVn1AipNG_90Cw hZktyFySOVWz0xApZZnl24a8zrc9JiTNOxs7ph5z7g1hah.wjKqq.Rskbavp ka5SUbhoDjrjDdNgHBHuLZnIMLazgIi6uxnmdf0j_6BXJnq5aafcMV3JdbBW Bv0zORlUtDIYW5pXd1LqIbTc47c4j0EeSGwIg.WM4inXfqpBcbo1difyYKDx Ze6UN1GdRUJD2zM8s_f2TvzgcfCpy7BD5Ma8GdgbqtzBj1roibqQmEdnS.h_ q2OLTIba18GqzwrrK4_EXhNi5YJGwnfwdmwVJ_MmPFy.SatoJNJFzP4flXmm hmUMb1DDt6FLJGob58Jmk87b7JSJgrlsjRy02puf_4hBdv_E7y7Lqw02IyUR C3AALCZiwewH0Iz.QDf.U4DN8W4FV.qP5_ofv4Xh6WtWRgWWjKHJ86zU- X-Yahoo-SMTP: mpGJl6eswBD2IBufoVEg0Pa8gg-- Received: from WolfDog (polobo@24.93.28.86 with login) by smtp108.prem.mail.ac4.yahoo.com with SMTP; 06 Dec 2012 15:44:18 -0800 PST From: "David Johnston" To: =?UTF-8?Q?'Pavel_Arno=C5=A1t'?= , References: <5097e057-c9b9-42f0-bed0-219eab05bb7d@googlegroups.com> <50C0E09A.4070408@ttc-cmc.net> <014101cdd3e0$a9a302a0$fce907e0$@yahoo.com> <5a57e55f-1b8f-4f37-a271-af9fb1a9ffab@googlegroups.com> <016e01cdd3f5$1dbdaaf0$593900d0$@yahoo.com> <51765e16-c35e-412d-b2f4-f8ab1a67f2f3@googlegroups.com> In-Reply-To: Subject: Re: Statement.setQueryTimeout() with autoCommit=false Date: Thu, 6 Dec 2012 18:44:04 -0500 Message-ID: <01b301cdd40b$93babcf0$bb3036d0$@yahoo.com> MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Mailer: Microsoft Outlook 14.0 Thread-Index: AQF71Xk46Ti56BxJT15wxGI4l97bCgL5hfPWAUAjiNcC3ghMCQGv1N9rAsnzK+IB1RxAiQHkJzkmmDYUfoA= Content-Language: en-us X-Pg-Spam-Score: -2.0 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-jdbc Precedence: bulk Sender: pgsql-jdbc-owner@postgresql.org I would suggest you ignore the "conn.commit()" call and instead create a se= parate statement "COMMIT;" and attach a statement timeout to that and then = execute that statement. I would think that the only thing you lose is the = ability to allow the driver to determine what the correct "commit;" command= but this seems cross-database safe enough regardless. I'll leave it to you to decide whether setting a fixed time-limit on the "C= OMMIT;" statement is wise in your situation. David J. > -----Original Message----- > From: pgsql-jdbc-owner@postgresql.org [mailto:pgsql-jdbc- > owner@postgresql.org] On Behalf Of Pavel Arno=C5=A1t > Sent: Thursday, December 06, 2012 5:58 PM > To: pgsql-jdbc@postgresql.org > Subject: Re: [JDBC] Statement.setQueryTimeout() with autoCommit=3Dfalse >=20 > I think that this is the reason why it doesn't work: >=20 > https://github.com/pgjdbc/pgjdbc/blob/master/org/postgresql/jdbc2/Abstr > actJdbc2Statement.java#L561 >=20 > INSERT command is executed (immediately) and timer is canceled (also > immediately), so there is no guard against query timeout when transaction= is > commited. That's unfortunate, for me at least. >=20 > On Thursday, December 6, 2012 10:17:34 PM UTC+1, Pavel Arno=C5=A1t wrote: > > I added e.printStackTrace() to catch block, just to be sure, and no exc= eption > is thrown. I described result poorly, code with TimerTask does not > *timeouts*, it *ends* after 5 seconds without error, just like my first > example without explicit transaction and autoCommit set to true. > > > > > > > > According to javadoc, st.cancel() after st.execute() should be ok. > > > > > > > > Does someone use synchronous replication? Without query timeouts, it's > not very usable IMO. > > > > > > > > On Thursday, December 6, 2012 10:03:17 PM UTC+1, "David Johnston" > wrote: > > > > > It may be that I am wrong and at the moment haven't tested your > > > examples but > > > > > > > > > > it seems odd that you can st.cancel() after st.execute() without > > > getting > > > > > > > > > > some kind of exception (which you are ignoring in your catch block). > > > > > > > > > > Without some more detail I either need to do some testing on my own > > > or leave > > > > > > > > > > it to more qualified individuals to help. I'll admit I am making > > > untested > > > > > > > > > > assumptions here about how the interaction should behave (but often > > > my idea > > > > > > > > > > of "should behave" differs from reality). > > > > > > > > > > > > > > > > > > > > David J. > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > -----Original Message----- > > > > > > > > > > > From: pgsql-jdbc-owner@postgresql.org [mailto:pgsql-jdbc- > > > > > > > > > > > owner@postgresql.org] On Behalf Of Pavel Arno=C4=8F=C5=BC=CB=9Dt > > > > > > > > > > > Sent: Thursday, December 06, 2012 3:33 PM > > > > > > > > > > > To: pgsql-jdbc@postgresql.org > > > > > > > > > > > Subject: Re: [JDBC] Statement.setQueryTimeout() with > > > > autoCommit=3Dfalse > > > > > > > > > > > > > > > > > > > > > > If that's how it works, why this code timeouts after 5 seconds?: > > > > > > > > > > > > > > > > > > > > > > -- > > > > > > > > > > > Connection conn =3D DriverManager.getConnection(url, props); > > > > > > > > > > > conn.setAutoCommit(false); > > > > > > > > > > > final PreparedStatement st =3D conn.prepareStatement("INSERT > > > > INTO > > > > > > > > > > test > > > > > > > > > > > VALUES('xxx')"); > > > > > > > > > > > st.setQueryTimeout(5); > > > > > > > > > > > st.execute(); > > > > > > > > > > > > > > > > > > > > > > Timer timer =3D new Timer(true); > > > > > > > > > > > > > > > > > > > > > > TimerTask cancelTimer =3D new TimerTask() { > > > > > > > > > > > public void run() { > > > > > > > > > > > try { > > > > > > > > > > > st.cancel(); > > > > > > > > > > > } catch (SQLException e) { } > > > > > > > > > > > } > > > > > > > > > > > }; > > > > > > > > > > > > > > > > > > > > > > timer.schedule(cancelTimer, 5000); > > > > > > > > > > > > > > > > > > > > > > conn.commit(); > > > > > > > > > > > -- > > > > > > > > > > > > > > > > > > > > > > Quick look at AbstractJdbc2Statement.execute() shows me that > > > > > > > > > > > setQueryTimeout() works with Timer/TimerTask like this one. > > > > > > > > > > > > > > > > > > > > > > Thanks, > > > > > > > > > > > Pavel > > > > > > > > > > > > > > > > > > > > > > On Thursday, December 6, 2012 7:36:53 PM UTC+1, "David Johnston" > wrote: > > > > > > > > > > > > > -----Original Message----- > > > > > > > > > > > > > > > > > > > > > > > > > From: pgsql-jdbc-owner@postgresql.org [mailto:pgsql-jdbc- > > > > > > > > > > > > > > > > > > > > > > > > > owner@postgresql.org] On Behalf Of dmp > > > > > > > > > > > > > > > > > > > > > > > > > Sent: Thursday, December 06, 2012 1:15 PM > > > > > > > > > > > > > > > > > > > > > > > > > To: pgsql-jdbc@postgresql.org > > > > > > > > > > > > > > > > > > > > > > > > > Cc: pavel.arnost@loutka.cz > > > > > > > > > > > > > > > > > > > > > > > > > Subject: Re: [JDBC] Statement.setQueryTimeout() with > > > > > > > > > > > > > autoCommit=3Dfalse > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > 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 requ= ired. > > > > > > > > > > > > The > > > > > > > > > > > > > > > > > > > > > > > > transaction itself does not constitute a statement and as such > > > > > it can > > > > > > > > > > > > run > > > > > > > > > > > > > > > > > > > > > > > > indefinitely long regardless of the presence of a statement timeo= ut. > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > 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, > > > > > > > > > > > > > > > > > > > > > > > > > > wrote: > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > Hi, > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > does setQueryTimeout work with autoCommit=3Dfalse? 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-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 > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > -- > > > > > > > > > > > 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 >=20 >=20 > -- > Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org) To make chan= ges > to your subscription: > http://www.postgresql.org/mailpref/pgsql-jdbc --=20 Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-jdbc