From: Tom Lane <tgl@sss.pgh.pa.us>
To: Christopher BROWN <brown@reflexe.fr>
Cc: pgsql-jdbc <pgsql-jdbc@postgresql.org>
Subject: Re: Handling transaction failure due to concurrency errors
Date: Fri, 02 Mar 2018 10:10:07 -0500
Message-ID: <26956.1520003407@sss.pgh.pa.us> (raw)
In-Reply-To: <CAHL_zcOcnBhHhbLenk0xt43i2v8sO6C5RX2ntVMErbKDc+cuWw@mail.gmail.com>
References: <CAHL_zcOcnBhHhbLenk0xt43i2v8sO6C5RX2ntVMErbKDc+cuWw@mail.gmail.com>
Christopher BROWN <brown@reflexe.fr> writes:
> I have an application running on a server, that (once per hour, in
> general) imports batches of data across several tables. The INSERT
> and UPDATE operations apply to several tables, and are executed in a
> specific repeatable order, all within one big TRANSACTION_SERIALIZABLE
> operation (one commit at the end, no partial commits or rollbacks). It
> almost always works without error. The files are provided from an
> external organisation, and when an error occurs, they are
> automatically notified by e-mail. Sometimes there is inconsistent
> data in the files, so they need to know when to fix this.
> However, sometimes it fails even when there's nothing wrong with their
> file, and the message indicates a transaction concurrency error. I'm
> having trouble isolating the error; normally the tables affected by
> the transaction aren't affected by any other action (they are normally
> read by other processes to create transformed data in other tables).
The short answer, most likely, is that the interlocks that check
for serializability violations are approximate in the conservative
direction, and will sometimes throw a serializability error even when
the changes made by two concurrent transactions didn't really conflict.
Basically, if you use SERIALIZABLE mode, you *must* be prepared to retry
on serialization failure, and you shouldn't really question too hard
why you got such an error. It's the price you pay for not having to
analyze the concurrent behavior of your application logic in detail.
What you might consider is automatically retrying a few times, and only
kicking out an error for human consideration if the serializability
failure seems persistent.
regards, tom lane
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: tgl@sss.pgh.pa.us, brown@reflexe.fr
Subject: Re: Handling transaction failure due to concurrency errors
In-Reply-To: <26956.1520003407@sss.pgh.pa.us>
References: <CAHL_zcOcnBhHhbLenk0xt43i2v8sO6C5RX2ntVMErbKDc+cuWw@mail.gmail.com> <26956.1520003407@sss.pgh.pa.us>
* 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