Received: from maia.hub.org (maia-5.hub.org [200.46.204.29]) by mail.postgresql.org (Postfix) with ESMTP id 2F8D6632FCE for ; Sun, 4 Jul 2010 06:59:50 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.29]) (amavisd-maia, port 10024) with ESMTP id 77798-05 for ; Sun, 4 Jul 2010 09:59:43 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from progressive.micfo.com (progressive.micfo.com [174.34.188.2]) by mail.postgresql.org (Postfix) with ESMTP id 10D996325DA for ; Sun, 4 Jul 2010 06:59:42 -0300 (ADT) Received: from 87-204-194-135.dg-net.pl ([87.204.194.135]:55001 helo=radek.localnet) by progressive.micfo.com with esmtpsa (TLSv1:AES256-SHA:256) (Exim 4.69) (envelope-from ) id 1OVLz8-0001yi-7g for pgsql-jdbc@postgresql.org; Sun, 04 Jul 2010 04:59:38 -0500 From: =?utf-8?q?Rados=C5=82aw_Smogura?= To: pgsql-jdbc@postgresql.org Subject: Re: Unable to commit: transaction marked for rollback Date: Sun, 4 Jul 2010 11:59:48 +0200 User-Agent: KMail/1.13.3 (Linux/2.6.32-gentoo-r7; KDE/4.4.4; x86_64; ; ) References: <20100701181528.GA97516@mr-paradox.net> <201007031036.46492.mail@smogura.eu> <4C2FEFE6.7010306@postnewspapers.com.au> In-Reply-To: <4C2FEFE6.7010306@postnewspapers.com.au> MIME-Version: 1.0 Content-Type: Text/Plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <201007041159.48509.rsmogura@softperience.eu> X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - progressive.micfo.com X-AntiAbuse: Original Domain - postgresql.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - softperience.eu X-Source: X-Source-Args: X-Source-Dir: X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.9 tagged_above=-10 required=5 tests=BAYES_00=-1.9 X-Spam-Level: X-Archive-Number: 201007/17 X-Sequence-Number: 20682 Unfortunatly in my apps I'm using JPA bridges and I don't belive that those= =20 use savepoints. Bad in this is that if I do mass processing it's obvious th= at=20 some "records" can be badly processed, and I don't want to break transactio= n,=20 (much more with JPA I can't use savepoints because there is no fixed point = of=20 send changes to database). I just want to write in this transaction=20 information to 2nd table or mark record as failed. Yesterday I realised that my application can not work as I suspected. I nee= d=20 to test it for this special case. In any way I think about simple and speci= al=20 patch, just and only for JPA bridges to add SAVEPOINT before each query. Dnia niedziela 04 lipiec 2010 o 04:20:22 Craig Ringer napisa=C5=82(a): > On 03/07/10 16:36, Rados=C5=82aw Smogura wrote: > > I've looked at error from your example, because I didn't belived such > > behavior. Unfortunatly it's true. Postgresql disallow to execute next > > statement if error occured - this is realy bad approach, because error > > can be from dupliacte keys etc. :( >=20 > If you want to handle errors and continue, use a subtransaction with > BEGIN SAVEPOINT and ROLLBACK TO SAVEPOINT. >=20 > Most of the time it's a performance advantage - and perfectly suitable > for apps - to avoid keeping a rollback point for each statement, and > instead chuck the whole transaction away if something goes wrong. Most > apps expect to retry the whole transaction if anything goes wrong > anyway, since it's often hard to tell if the issue can be resolved by > retrying just one (possibly altered) statement or not. >=20 > It's also safer. If Pg allowed a transaction to continue after an INSERT > failed, it'd end up committing an incomplete set of the requested > changes and hoping that the user/app noticed. I don't like that - I'd > much rather have to explicitly handle the issue, and otherwise have an > error in a transaction be an error that aborts the transaction, not just > the particular statement that caused the error. >=20 > For bulk insertion, you're almost always better off copying the data > into a temporary table, cleaning it up if necessary, then using INSERT > INTO ... SELECT to insert it duplicate-free. >=20 > I guess an optional mode that issued an implicit savepoint before each > transaction and allowed "ROLLBACK TO LAST STATEMENT" would be nice, > though, as a convenience to avoid all the savepoint management on the > rare occasions when you do want statement-level rollback. >=20 > -- > Craig Ringer