Re: #XX000: ERROR: tuple concurrently updated - Mailing list pgsql-general

From Dominique Devienne
Subject Re: #XX000: ERROR: tuple concurrently updated
Date
Msg-id CAFCRh-8YN2GUkpo8PkdouGf55FzzkjAhV8t-gj0i5zfbz8i_fg@mail.gmail.com
Whole thread Raw
In response to Re: #XX000: ERROR: tuple concurrently updated  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: #XX000: ERROR: tuple concurrently updated
List pgsql-general
On Thu, Feb 20, 2025 at 4:27 PM Tom Lane <tgl@sss.pgh.pa.us> wrote:
Dominique Devienne <ddevienne@gmail.com> writes:
> Hi. A tester just tried to restore two custom backups (not official
> PostgreSQL ones) concurrently.
> ...
> The second session completed OK.
> But the first session errors out with:

> Error: DDL Error: GRANT USAGE ON SCHEMA "SCH1", "SCH2" TO "SCH2:RO",
> "SCH2:RW", "SCH2:SU": #XX000: ERROR:  tuple concurrently updated

> Thus I'm trying to understand what's going on.

Since both restores tried to grant some permissions on SCH1, they
both had to update SCH1's pg_namespace row (specifically nspacl).
We have no support for concurrent updates in the catalog-manipulation
code, so if the second run arrives at that step before the first
one has committed its pg_namespace change, you get this error.

Thanks for confirming Tom.
 
> Is the issue related to trying to change SCHEMA ACLs for SCH1 concurrently,
> in two long running transactions? How am I supposed to resolve this?

The window is probably too small to hit if each restore is committing
as it goes, but if you run in --single-transaction mode then this
isn't surprising.  I'd say don't try to run concurrent restores.

First, I'm not in psql, but my own code. And as mentioned, I'm already in the equivalent,
doing everything (DDLs and DMLs) in a single transaction.

Second, not doing concurrent restores is not an option.

So I need to separate operations related to SCH2,3,..., which are all independent,
and SCH1 which is shared, as separate long running and short transactions, respectively.
With perhaps some retry logic on the SCH1, just in case. --DD

pgsql-general by date:

Previous
From: Tom Lane
Date:
Subject: Re: #XX000: ERROR: tuple concurrently updated
Next
From: Dominique Devienne
Date:
Subject: DROP ROLE as SUPERUSER