From: Radosław Smogura <rsmogura@softperience.eu>
To: pgsql-jdbc@postgresql.org
Subject: Re: Unable to commit: transaction marked for rollback
Date: Sun, 4 Jul 2010 11:59:48 +0200
Message-ID: <201007041159.48509.rsmogura@softperience.eu> (raw)
In-Reply-To: <4C2FEFE6.7010306@postnewspapers.com.au>
References: <20100701181528.GA97516@mr-paradox.net>
<201007031036.46492.mail@smogura.eu>
<4C2FEFE6.7010306@postnewspapers.com.au>
Unfortunatly in my apps I'm using JPA bridges and I don't belive that those
use savepoints. Bad in this is that if I do mass processing it's obvious that
some "records" can be badly processed, and I don't want to break transaction,
(much more with JPA I can't use savepoints because there is no fixed point of
send changes to database). I just want to write in this transaction
information to 2nd table or mark record as failed.
Yesterday I realised that my application can not work as I suspected. I need
to test it for this special case. In any way I think about simple and special
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ł(a):
> On 03/07/10 16:36, Radosław 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. :(
>
> If you want to handle errors and continue, use a subtransaction with
> BEGIN SAVEPOINT and ROLLBACK TO SAVEPOINT.
>
> 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.
>
> 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.
>
> 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.
>
> 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.
>
> --
> Craig Ringer
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: rsmogura@softperience.eu
Subject: Re: Unable to commit: transaction marked for rollback
In-Reply-To: <201007041159.48509.rsmogura@softperience.eu>
References: <20100701181528.GA97516@mr-paradox.net> <201007031036.46492.mail@smogura.eu> <4C2FEFE6.7010306@postnewspapers.com.au> <201007041159.48509.rsmogura@softperience.eu>
* 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