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>
Cc: Zhijie Hou <houzhijie22(at)gmail(dot)com>, Alexander Lakhin <exclusion(at)gmail(dot)com>, 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-11-02 09:56:48
Message-ID: OS7PR01MB183171494F6DA907EB7D722FFF56A2@OS7PR01MB18317.jpnprd01.prod.outlook.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi Vignesh,

> Thanks for reporting this issue, I was able to reproduce this. It was
> reachable because for a partitioned table OpenTableList() does not
> lock the partitions (only a non-partitioned inheritance parent gets
> find_all_inheritors() with ShareUpdateExclusiveLock), so ADD TABLE
> holds a lock on the root only. The partitions are collected later in
> GetPubPartitionOptionRelations() with find_all_inheritors(NoLock).
> Dropping a partition takes AccessExclusiveLock on the partition and on
> its direct parent, so a direct child conflicts with the ALTER through
> the root, but a grandchild does not.
> The updated v3 version patch has the changes to handle the same.

While investigating this issue, I found another case where a cache lookup can
fail. Unlike the previously discussed case, this failure occurs while
find_all_inheritors() is still building the relation list, before
InvalidatePublicationRels() is called. Do you think we should also fix,
or should be done in other places?

The issue can be reproduced with a multi-level partition tree [1]. Note that p1
must be created before p2. Brief steps:

0. Run "ALTER PUBLICATION ADD TABLE root".
1. find_all_inheritors(root, NoLock, ...) adds root to rels_list.
2. It processes "root" and appends "p1" and "p2" to rels_list.
3. It processes "p1" and appends "trigger".
4. It processes "p2" and appends "victim".
5. Another backend drops "victim". This cannot be conflicted because the DROP command
acquires locks only for the table (victim) and its direct parent (p2).
6. The first backend processes "trigger". Invalidation messages can be handled
here because the table has a child and system catalog is opened.
7. It processes "victim". Since it's dropped and the inval message is handled,
it causes the cache lookup failure.

[1]
root
|---- p1
| +---- trigger
| +---- other
+---- p2
+---- victim

Best regards,
Hayato Kuroda
FUJITSU LIMITED

Attachment Content-Type Size
v1-nocfbot-0001-Reproduce-the-cache-lookup-failure.patch application/octet-stream 5.1 KB

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Jim Jones 2026-11-02 10:06:34 Re: Reject access to unlogged tables in contrib modules
Previous Message Zhijie Hou 2026-11-02 09:42:10 Re: [PATCH] Fix incorrect logical replication updates with a shared leaf partition