Re: DROP USER MAPPING doesn't acquire lock on its server

From: Kirill Reshke <reshkekirill(at)gmail(dot)com>
To: shihao zhong <zhong950419(at)gmail(dot)com>
Cc: Jeff Davis <pgsql(at)j-davis(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: DROP USER MAPPING doesn't acquire lock on its server
Date: 2026-12-03 07:04:41
Message-ID: CALdSSPjDouhV3WsBvP3ZxcsrAreiW9gSTkyAdRpVRO8afmjrQw@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Thu, 3 Dec 2026 at 08:55, shihao zhong <zhong950419(at)gmail(dot)com> wrote:
>
> Hi Kirill,

Hi! Thanks for looking into this.

> Thanks for the report. The same race hits every command that looks up a
> server by name. With your fix I still get "cache lookup failed" from
> ALTER USER MAPPING and DROP USER MAPPING. CREATE FOREIGN TABLE and
> IMPORT FOREIGN SCHEMA fail the same way. Maybe one shared helper that
> takes the lock could fix them all?

Yes indeed. I reproduced same issue with

CREATE USER MAPPING
ALTER USER MAPPING
DROP USER MAPPING
CREATE FOREIGN TABLE
IMPORT FOREIGN SCHEMA

CREATE SUBSCRIPTION ... SERVER
ALTER SUBSCRIPTION ... SERVER.

five mapping/table/import statements all return XX000. The two
subscription statements report ERROR: cache lookup failed for foreign
server <oid>

Attached fixes this using a helper function in all call sites.

>
> Also, with the fix your test no longer reaches the injection point, I think this is just for
> reproduce, not for submit?

Yes

--
Best regards,
Kirill Reshke

Attachment Content-Type Size
0001-lock-foreign-server-lookups.diff application/octet-stream 6.0 KB

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Michael Paquier 2026-12-03 07:05:23 Re: GetNewOidWithIndex() can reuse a TOAST value ID while its chunks are still in the heap
Previous Message Michael Paquier 2026-12-03 07:04:10 Re: [PATCH v2] Reuse slot helpers in pg_get_replication_slots and slot copy