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 1kD7U2-00057Z-Qm for pgsql-general@arkaria.postgresql.org; Tue, 01 Sep 2020 14:42:03 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1kD7U1-0008Gn-PT for pgsql-general@arkaria.postgresql.org; Tue, 01 Sep 2020 14:42:01 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kD7U0-0008Gg-05 for pgsql-general@lists.postgresql.org; Tue, 01 Sep 2020 14:42:01 +0000 Received: from wout1-smtp.messagingengine.com ([64.147.123.24]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kD7Tw-0000S8-Un for pgsql-general@lists.postgresql.org; Tue, 01 Sep 2020 14:41:58 +0000 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.west.internal (Postfix) with ESMTP id B4BCB493; Tue, 1 Sep 2020 10:41:54 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute4.internal (MEProxy); Tue, 01 Sep 2020 10:41:54 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aklaver.com; h= subject:to:references:from:message-id:date:mime-version :in-reply-to:content-type:content-transfer-encoding; s=fm3; bh=q gzGvBmdBafuJJmCyPHWSsahU3HQxlaOftmuNzBFbis=; b=CYu2HyutXecOjMBmM mXMPH2vmPBHLLKoG0D88o18wTlGPbclxsNCklLjo+l8aYPDcx1cAkbtV/Tw2uXtn 7V7I3x2cqNVNAUgc8Fj4TxbAN62KzotiVyhVWj+ICYODxnsayek2Mwk1yP10FfZY 5nNLvHwupCli1ReeTVIq9KvESxgEQNgJKpRLtfFIs0y1krBGOF25KV/Rrb0jYxPW MYJ4cZhPKASn+yL1HlPmvMmLkhfla9F6ISfvDGTkmoIuyvmI6wESAflIXlqksB/g 86Zj21hq/MqXPsNKunV+YYEVaxznx/Bsgczn7dacLIRsNLKO0125erJsLKZDMp76 4zuuw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm3; bh=qgzGvBmdBafuJJmCyPHWSsahU3HQxlaOftmuNzBFb is=; b=GU851ZzjfObgQ8r/OIKXp8mWUVhsjHk1NIruAmfhWN0TJnm0QXLCm2eU8 ln5Gpvet0kZoZPLokoV4ZDfSI536oOJpkXVz8AxRTH69PT3RL0AaqqDxxzQ9fkLm D2ScSMxzd5D9cS5tjSvTp+hOBZnnoWOhjn9RR1VeyI30mO/NPGv++pSNcjztpPWI cKLbFv8QJsEzo5sqqZ9kkZFyqpRrPXLOZAr2G4s1defC0T3nyIulxIQ5hUxwB9CP FU0HD70/hnYAG8QLTiYnpXTuHPolijUmeEpb9el7UEmLPoTRtZMQOp1ftGyq7v/o UKbSOX70qvFwfBHi4oeb9rtoptqmg== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduiedrudefjedgkeduucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepuffvfhfhkffffgggjggtgfesthejredttdefjeenucfhrhhomheptegurhhi rghnucfmlhgrvhgvrhcuoegrughrihgrnhdrkhhlrghvvghrsegrkhhlrghvvghrrdgtoh hmqeenucggtffrrghtthgvrhhnpeevteejtdeikeetfefhhffhteelvdekffevudegjeeu kefhgfdvieeliedtkeevhfenucffohhmrghinhepphhoshhtghhrvghsqhhlrdhorhhgne cukfhppeejhedrudejvddrhedrvdefudenucevlhhushhtvghrufhiiigvpedtnecurfgr rhgrmhepmhgrihhlfhhrohhmpegrughrihgrnhdrkhhlrghvvghrsegrkhhlrghvvghrrd gtohhm X-ME-Proxy: Received: from [192.168.1.3] (75-172-5-231.tukw.qwest.net [75.172.5.231]) by mail.messagingengine.com (Postfix) with ESMTPA id 7F82A3280059; Tue, 1 Sep 2020 10:41:53 -0400 (EDT) Subject: Re: Trigger transaction isolation To: Dirk Lattermann , pgsql-general@lists.postgresql.org References: <20200825111235.2c7193f0@walter> <20200901160706.169adf76@walter> From: Adrian Klaver Message-ID: Date: Tue, 1 Sep 2020 07:41:52 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.12.0 MIME-Version: 1.0 In-Reply-To: <20200901160706.169adf76@walter> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk 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 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