pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Sylvain Déve <sylvain.deve@protonmail.com>
Cc: pgsql-general@lists.postgresql.org
Subject: Re: Update concurrency
Date: Mon, 20 Dec 2021 11:38:43 -0500
Message-ID: <2446966.1640018323@sss.pgh.pa.us> (raw)
In-Reply-To: <b9OqO_gmgD3ud4szSECPwWvNnReLOk28QJI43OxF6hn6aw76aCc3UeDkqdlcZOPbiwVmgpky3GcQIio7KxuuSiUFYty-UAQ8Np0TBTr6dFM=@protonmail.com>
References: <-zxRtNEMT5cJjoFNR4LphpHl907G9wjMd-xShnDUyjZg5cgXZQpRdsNHe6OY96_8eyP9s0cyttLKUwv4FyRrirbUGeEoQe22M0lpaFJSGuo=@protonmail.com>
	<2377043.1640012857@sss.pgh.pa.us>
	<b9OqO_gmgD3ud4szSECPwWvNnReLOk28QJI43OxF6hn6aw76aCc3UeDkqdlcZOPbiwVmgpky3GcQIio7KxuuSiUFYty-UAQ8Np0TBTr6dFM=@protonmail.com>

[ please keep the list cc'd ]

=?utf-8?Q?Sylvain_D=C3=A9ve?= <sylvain.deve@protonmail.com> writes:
> Indeed I removed the important part here... I was including a function definition ("create or replace function ...") in the call too. This was temporary and dirty. After moving the definition of the function to the initialization of the database, it solved everything... Defining the same function multiple times, and I presume more or less at the same time, led to problems. The table update is carried out finally without any problem...

Hah, now I can reproduce it:

regression=# create or replace function foo(int) returns int as 'select 1' language sql;
CREATE FUNCTION
regression=# begin;
BEGIN
regression=*# create or replace function foo(int) returns int as 'select 1' language sql;
CREATE FUNCTION

... in another session:

regression=# create or replace function foo(int) returns int as 'select 1' language sql;
<<blocks>>

... in first session:

regression=*# 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





view thread (4+ messages)

Message-ID: <2446966.1640018323@sss.pgh.pa.us>
Permalink:  ../2446966.1640018323@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/2446966.1640018323@sss.pgh.pa.us

 · 

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: tgl@sss.pgh.pa.us, sylvain.deve@protonmail.com
  Subject: Re: Update concurrency
  In-Reply-To: <2446966.1640018323@sss.pgh.pa.us>
  References: <-zxRtNEMT5cJjoFNR4LphpHl907G9wjMd-xShnDUyjZg5cgXZQpRdsNHe6OY96_8eyP9s0cyttLKUwv4FyRrirbUGeEoQe22M0lpaFJSGuo=@protonmail.com> <2377043.1640012857@sss.pgh.pa.us> <b9OqO_gmgD3ud4szSECPwWvNnReLOk28QJI43OxF6hn6aw76aCc3UeDkqdlcZOPbiwVmgpky3GcQIio7KxuuSiUFYty-UAQ8Np0TBTr6dFM=@protonmail.com> <2446966.1640018323@sss.pgh.pa.us>

* 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