From: Daniel Verite <daniel@manitou-mail.org>
To: shalini@saralweb.com
Cc: Rene Romero Benavides <rene.romero.b@gmail.com>
Cc: Postgres General <pgsql-general@postgresql.org>
Subject: Re: Tuple concurrency issue in large objects
Date: Wed, 18 Dec 2019 16:05:18 +0100
Message-ID: <70757632-58a5-4bf1-a4b8-af2ed5a4fa9a@manitou-mail.org> (raw)
In-Reply-To: <0874ff74-7ffc-4a1d-ba26-1a617bb34c59@email.android.com>
Shalini wrote:
> Could you also please state the reason why is it happening in case
> of large objects? Because concurrent transactions are very well
> handled for other data types, but the same is not happening for
> lobs. Is it because the fomer are stored in toast table and there is
> no support for concurrent txns in pg_largeobject table?
Keeping in mind that large objects are not a datatype, but rather a
functionality that is built on top of the bytea and oid datatypes plus
a set of functions, I wouldn't say that concurrent writes would be
better handled if you had a table: document(id serial, contents bytea)
with "contents" being indeed toastable.
To illustrate with a basic example: transactions Tx1 and Tx2
want to update the contents of the same document concurrently,
with this order of execution:
Tx1: begin
Tx1: update document set contents=... where id=...
Tx2: begin
Tx2: update the same document (gets blocked)
Tx1: commit
Tx2: commit
If using the read committed isolation level, Tx2 will be put to wait
until Tx1 commits, and then the update by Tx1 will be overwritten by
Tx2. That's a well known anomaly known as a "lost update", and
probably not what you want.
If using a better isolation level (repeatable read or serializable),
the update by Tx2 will be rejected with a serialization failure,
which, to me, seems the moral equivalent of the "Tuple concurrently
updated" error you're reporting with large objects.
When this occurs, your application can fetch the latest value in a new
transaction and see how it can apply its change to the new value,
unless another conflict arises and so on.
In short, the best the database can do in case of conflicting writes
is to inform the application. It can't know which write should be
prioritized or if the changes should be merged before being written.
Best regards,
--
Daniel Vérité
PostgreSQL-powered mailer: http://www.manitou-mail.org
Twitter: @DanielVerite
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-general@postgresql.org
Cc: daniel@manitou-mail.org, shalini@saralweb.com, rene.romero.b@gmail.com
Subject: Re: Tuple concurrency issue in large objects
In-Reply-To: <70757632-58a5-4bf1-a4b8-af2ed5a4fa9a@manitou-mail.org>
References: <0874ff74-7ffc-4a1d-ba26-1a617bb34c59@email.android.com> <70757632-58a5-4bf1-a4b8-af2ed5a4fa9a@manitou-mail.org>
* 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