Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kD7nd-00064p-6Q for pgsql-general@arkaria.postgresql.org; Tue, 01 Sep 2020 15:02:17 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1kD7na-0005kJ-Qc for pgsql-general@arkaria.postgresql.org; Tue, 01 Sep 2020 15:02:14 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kD7na-0005kB-IT for pgsql-general@lists.postgresql.org; Tue, 01 Sep 2020 15:02:14 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kD7nX-0006cE-KT for pgsql-general@lists.postgresql.org; Tue, 01 Sep 2020 15:02:14 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 081F21wh054138; Tue, 1 Sep 2020 11:02:01 -0400 From: Tom Lane To: Adrian Klaver cc: Dirk Lattermann , pgsql-general@lists.postgresql.org Subject: Re: Trigger transaction isolation In-reply-to: References: <20200825111235.2c7193f0@walter> <20200901160706.169adf76@walter> Comments: In-reply-to Adrian Klaver message dated "Tue, 01 Sep 2020 07:41:52 -0700" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <54136.1598972521.1@sss.pgh.pa.us> Date: Tue, 01 Sep 2020 11:02:01 -0400 Message-ID: <54137.1598972521@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Adrian Klaver writes: > 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 No, a trigger is part of the calling transaction. There's nothing special about it other than the condition causing the call; visibility rules are the same as for any other function. So the answer to the OP's question depends on the transaction's isolation level and (for typical PLs) on whether the function is VOLATILE or not. serializable -> the transaction's initial snapshot is used throughout non serializable, volatile function -> each statement in the function takes a fresh snapshot non serializable, non-volatile function -> the function uses a single snapshot. For a non-deferred trigger, I think it shares the snapshot used by the triggering query. Not sure about exactly when the snapshot is taken for a deferred trigger. regards, tom lane