pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Adrian Klaver <adrian.klaver@aklaver.com>
To: Dirk Lattermann <dlatt@alqualonde.de>
To: pgsql-general@lists.postgresql.org
Subject: Re: Trigger transaction isolation
Date: Tue, 1 Sep 2020 07:41:52 -0700
Message-ID: <fbdb4b5b-3616-7426-34c4-982e101186c0@aklaver.com> (raw)
In-Reply-To: <20200901160706.169adf76@walter>
References: <20200825111235.2c7193f0@walter>
	<20200901160706.169adf76@walter>

On 9/1/20 7:07 AM, Dirk Lattermann wrote:
> Hello!
> 
> Since unfortunately nobody has yet replied to my question, I'd like to
> know if this is the right list to ask this question on or if I should
> try another mailing list.
> Maybe the answer is too obvious, but in that case I'd appreciate a
> short hint to help me finding it.
> Maybe it's a hard question, then the answer will be even more
> interesting...?

As I understand it a trigger function runs in its own transaction so the 
rules from below apply:

https://www.postgresql.org/docs/12/transaction-iso.html

13.2.1. Read Committed Isolation Level

> 
> Thanks again,
> Dirk Lattermann
> 
> On Tue, 25 Aug 2020 11:12:35 +0200
> Dirk Lattermann <dlatt@alqualonde.de> wrote:
> 
>> Hello,
>>
>> I'd like to understand the visibility of data changes made by other
>> transactions when executing SQL commands in a trigger function in READ
>> COMMITTED isolation level.
>> I could not find this covered in the trigger documentation (which
>> already has some good sections about SQL command visibility for
>> several trigger types), and I don't think it is practically possible
>> to infer this from observations of the behaviour.
>>
>> So, if during an SQL command that triggers a trigger, another
>> transaction commits, do the SQL commands in the trigger that start
>> after that commit see the changes of the other transaction or do they
>> see the state as it was when the triggering command was
>> started?
>>
>> If they do see the changes, then I could implement a
>> constraint check without race condition based on the contents of some
>> other table using a lock on that table (say, to check for relation
>> cycles, or, in the same table, to limit the number of records).
>> If they don't see the changes, then I fear the race condition free
>> check can only be implemented using the SERIALIZABLE isolation level,
>> which I cannot really use in my situation for performance reasons and
>> the retry overhead. I know that using a lock might lead to a
>> deadlock, but I'd want to give it a try.
>>
>> Thank you very much.
>> Dirk Lattermann
>>
>>
> 
> 
> 


-- 
Adrian Klaver
adrian.klaver@aklaver.com





view thread (4+ messages)  latest in thread

Message-ID: <fbdb4b5b-3616-7426-34c4-982e101186c0@aklaver.com>
Permalink:  ../fbdb4b5b-3616-7426-34c4-982e101186c0@aklaver.com/
Also on:    postgresql.org/message-id/fbdb4b5b-3616-7426-34c4-982e101186c0@aklaver.com

 · 

reply

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: adrian.klaver@aklaver.com, dlatt@alqualonde.de
  Subject: Re: Trigger transaction isolation
  In-Reply-To: <fbdb4b5b-3616-7426-34c4-982e101186c0@aklaver.com>
  References: <20200825111235.2c7193f0@walter> <20200901160706.169adf76@walter> <fbdb4b5b-3616-7426-34c4-982e101186c0@aklaver.com>

* 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