Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1qnM7q-00AiJq-88 for pgsql-general@arkaria.postgresql.org; Mon, 02 Oct 2023 16:50:30 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1qnM7o-00GHWF-0o for pgsql-general@arkaria.postgresql.org; Mon, 02 Oct 2023 16:50:28 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1qnM7n-00GHW5-L5 for pgsql-general@lists.postgresql.org; Mon, 02 Oct 2023 16:50:27 +0000 Received: from janus.karlpinc.com ([173.161.46.12] helo=smtp.karlpinc.com) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1qnM7k-007ouP-EL for pgsql-general@lists.postgresql.org; Mon, 02 Oct 2023 16:50:25 +0000 Received: from slate.karlpinc.com (unknown [192.168.1.14]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by smtp.karlpinc.com (Postfix) with ESMTPS id 43419A25A for ; Mon, 2 Oct 2023 11:49:52 -0500 (CDT) Received: from slate.karlpinc.com (localhost [IPv6:::1]) by slate.karlpinc.com (Postfix) with ESMTPS id 0ED143FD6B for ; Mon, 2 Oct 2023 11:49:52 -0500 (CDT) Date: Mon, 2 Oct 2023 11:49:42 -0500 From: "Karl O. Pinc" To: pgsql-general@lists.postgresql.org Subject: Trigger functions and parallelism Message-ID: <20231002114942.56a6f656@slate.karlpinc.com> X-Mailer: Claws Mail 3.17.8 (GTK+ 2.24.33; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hi, It's not entirely clear to me what the conditions are for function parallel safety. While the documentation seems pretty clear in most cases, there still some verbiage that requires knowledge of internals in order to be useful. What I'm looking for is some general statements about parallel safety for trigger functions. I don't know enough about parallelism to even know if it applies to data modification statements. It seems to me that, because raising any sort of exception affects transaction state, that triggers which validate data integrity and raise errors must be PARALLEL UNSAFE. But are any sort of AFTER INSERT trigger on a generated sequential key parallel UNSAFE because they access sequence state via NEW? Can something generic be said, like: "Most trigger functions should be declared PARALLEL UNSAFE (the default) with the possible exception of BEFORE triggers that raise no exceptions and control system behavior by their return value."? What can be said to provide some overview which gives guidance on parallelism to trigger authors? Regards, Karl Free Software: "You don't pay back, you pay forward." -- Robert A. Heinlein