RE: Test publication.sql racing with subscription.sql might fail due to cache lookup error

From: "Hayato Kuroda (Fujitsu)" <kuroda(dot)hayato(at)fujitsu(dot)com>
To: 'vignesh C' <vignesh21(at)gmail(dot)com>, Alexander Lakhin <exclusion(at)gmail(dot)com>
Cc: pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: RE: Test publication.sql racing with subscription.sql might fail due to cache lookup error
Date: 2026-10-13 06:54:30
Message-ID: OS7PR01MB18317D270D7F9C59B918173E4F59E2@OS7PR01MB18317.jpnprd01.prod.outlook.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi Vignesh,

> Thanks for reporting this Alexander.
> This fails because RemovePublicationSchemaById() calls
> GetSchemaPublicationRelations(), which collects relation OIDs using a
> catalog snapshot. If a relation is dropped concurrently after that
> snapshot, its OID can still be present in the returned list.
> InvalidatePublicationRels() then calls
> CacheInvalidateRelcacheByRelid() for that OID. By this point, the
> relation may already have been removed and its invalidation processed,
> so the lookup fails with:
> cache lookup failed for relation %u

To confirm, publication_add_schema()->GetSchemaPublicationRelations() gathers the
oid of relations without acquiring the lock. Therefore another process can drop
the relation and this can cause the cache lookup failure, right?

> I felt InvalidatePublicationRels() should simply skip relations that
> no longer exist. There is no relcache entry left to invalidate, and
> the DROP has already queued the required invalidation.

I checked your source, but isn't there still a whole that failure can happen?
Relation can be dropped after the SearchSysCache1().

How about the below? It tries to open the relation, and skip if cannot.
Relation cache can be invalidated via CacheInvalidateRelcache() instead of ...ByTuple().
```
if (list_length(relids) < MAX_RELCACHE_INVAL_MSGS)
{
foreach_oid(relid, relids)
{
Relation rel = try_table_open(relid, AccessShareLock);

if (rel == NULL)
continue;

CacheInvalidateRelcache(rel);
table_close(rel, AccessShareLock);
}
}
```

Best regards,
Hayato Kuroda
FUJITSU LIMITED

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Peter Smith 2026-10-13 07:01:01 Re: Proposal: Conflict log history table for Logical Replication
Previous Message Rui Zhao 2026-10-13 06:37:48 Re: Deprecation warnings on Rocky 10.2 with current dev branch