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 1mzLgW-0007KD-DN for pgsql-general@arkaria.postgresql.org; Mon, 20 Dec 2021 16:38:48 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1mzLgV-0004Or-5u for pgsql-general@arkaria.postgresql.org; Mon, 20 Dec 2021 16:38:47 +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 1mzLgU-0004Oi-SN for pgsql-general@lists.postgresql.org; Mon, 20 Dec 2021 16:38:46 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mzLgS-0004Fg-PU for pgsql-general@lists.postgresql.org; Mon, 20 Dec 2021 16:38:45 +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 1BKGchfa2446967; Mon, 20 Dec 2021 11:38:43 -0500 From: Tom Lane To: =?utf-8?Q?Sylvain_D=C3=A9ve?= cc: pgsql-general@lists.postgresql.org Subject: Re: Update concurrency In-reply-to: References: <-zxRtNEMT5cJjoFNR4LphpHl907G9wjMd-xShnDUyjZg5cgXZQpRdsNHe6OY96_8eyP9s0cyttLKUwv4FyRrirbUGeEoQe22M0lpaFJSGuo=@protonmail.com> <2377043.1640012857@sss.pgh.pa.us> Comments: In-reply-to =?utf-8?Q?Sylvain_D=C3=A9ve?= message dated "Mon, 20 Dec 2021 15:51:16 +0000" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <2446965.1640018323.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Mon, 20 Dec 2021 11:38:43 -0500 Message-ID: <2446966.1640018323@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk [ please keep the list cc'd ] =3D?utf-8?Q?Sylvain_D=3DC3=3DA9ve?=3D writes= : > Indeed I removed the important part here... I was including a function d= efinition ("create or replace function ...") in the call too. This was tem= porary and dirty. After moving the definition of the function to the initi= alization of the database, it solved everything... Defining the same funct= ion multiple times, and I presume more or less at the same time, led to pr= oblems. The table update is carried out finally without any problem... Hah, now I can reproduce it: regression=3D# create or replace function foo(int) returns int as 'select = 1' language sql; CREATE FUNCTION regression=3D# begin; BEGIN regression=3D*# create or replace function foo(int) returns int as 'select= 1' language sql; CREATE FUNCTION ... in another session: regression=3D# create or replace function foo(int) returns int as 'select = 1' language sql; <> ... in first session: regression=3D*# commit; COMMIT and now the second session fails with ERROR: tuple concurrently updated because both transactions are trying to update the same pre-existing row of pg_proc. (If the function didn't exist to start with, then you get "duplicate key value violates unique constraint" instead.) That's basically because internal catalog manipulations don't go to the same lengths as user queries do to handle concurrent-update scenarios nicely. I'm not sure what would be involved in making that better, but I am sure it'd be a lot of work :-( regards, tom lane