Re: BUG #19864: pg_get_publication_tables() gets cache lookup error after concurrent DROP PUBLICATION

From: shveta malik <shveta(dot)malik(at)gmail(dot)com>
To: Dilip Kumar <dilipbalaut(at)gmail(dot)com>
Cc: Zsolt Parragi <zsolt(dot)parragi(at)percona(dot)com>, pgsql-bugs(at)lists(dot)postgresql(dot)org, Ajin Cherian <itsajin(at)gmail(dot)com>, imchifan8(at)gmail(dot)com, Masahiko Sawada <sawada(dot)mshk(at)gmail(dot)com>, shveta malik <shvetamalik(at)gmail(dot)com>
Subject: Re: BUG #19864: pg_get_publication_tables() gets cache lookup error after concurrent DROP PUBLICATION
Date: 2026-11-16 04:55:48
Message-ID: CAJpy0uA5wq8w_NkjSkWu8AEc-2YKje-4PLrcJ6rP7n_Kbe8X8w@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

On Mon, Nov 16, 2026 at 9:24 AM shveta malik <shveta(dot)malik(at)gmail(dot)com> wrote:
>
> On Sat, Nov 14, 2026 at 4:18 PM Dilip Kumar <dilipbalaut(at)gmail(dot)com> wrote:
> >
> > On Fri, Nov 13, 2026 at 3:40 PM shveta malik <shveta(dot)malik(at)gmail(dot)com> wrote:
> > >
> > > On Fri, Nov 13, 2026 at 3:01 PM Zsolt Parragi <zsolt(dot)parragi(at)percona(dot)com> wrote:
> > > >
> > > > Hello
> > > >
> > > > There's still another remaining issue with the above patches, pointed
> > > > out by claude: a missing pg_publication_rel entry while the
> > > > publication still exists isn't always the partition-via-parent case,
> > > > the table could also have been removed from the publication
> > > > concurrently.
> > >
> > > Okay, thanks for reporting. I agree with the problem. It seems like
> > > another variation of commit 63e7a0d2c3 (due to DROP TABLE part), but
> > > it's also related to current thread because the publication is
> > > concurrently 'altered' (similar to original concurrent 'drop
> > > publication'). Therefore, I'm okay with incorporating the fix into the
> > > current patch. I have attached the fix as 003.
> > >
> > > v4-0001 is same as Ajin's v3-0001.
> > > v4-0002 fixes the wrong column list and filter for the last fetched
> > > table in a concurrently dropped publication.
> > > v4-0003 fixes the wrong column list and row filter for concurrently
> > > altered publication that drops a table.
> >
> > Thanks for the patch, Shveta. While testing, I see all the reported
> > cases are fixed but found another issue, check below test
> >
> > -- Setup
> > CREATE TABLE tbl_parent (a int) PARTITION BY RANGE (a);
> > CREATE TABLE tbl_part1 PARTITION OF tbl_parent FOR VALUES FROM (1) TO (10);
> > CREATE TABLE tbl_part2 PARTITION OF tbl_parent FOR VALUES FROM (10) TO (20);
> > CREATE PUBLICATION pub FOR TABLE tbl_parent WITH
> > (publish_via_partition_root = false);
> >
> > Session 1:
> > BEGIN;
> > LOCK TABLE tbl_part2 IN ACCESS EXCLUSIVE MODE;
> >
> > Session 2:
> > SELECT relid::regclass FROM pg_get_publication_tables('pub');
> > -- Emits tbl_part1, then blocks waiting on tbl_part2
> >
> > Session 1:
> > ALTER PUBLICATION pub SET (publish_via_partition_root = true);
> > COMMIT;
> >
> > Session 2:
> > relid
> > -----------
> > tbl_part1
> > (1 row)
> >
> > So while it was waiting on the lock on tbl_part2, we concurrently
> > updated publish_via_partition_root to true, and due to that the
> > inidividual partitions are not listed and it skipped tbl_part2,
> > whereas tbl_part1 is already listed, that was never valid either
> > before (tbl_part1, tbl_part2) or after (tbl_parent) the ALTER
> > PUBLICATION, what do you think?
>
> Agreed; the current result is wrong. It seems a regerssion of 0003;
> is_table_publishable_in_publication() was evaluated with the
> publication’s current 'publish_via_partition_root', while the list of
> relations was built on the first call with the old setting. So
> tbl_part2 looked “not published” even though only its representation
> changed. Since tbl_part1 has already been returned, we can’t produce
> the after-state (tbl_parent) without materializing the result, so I
> think the right answer is the before-state (tbl_part1, tbl_part2),
> which is also what HEAD returns. Thoughts?
>
> The way to achieve this is to let
> is_table_publishable_in_publication() decide based on the publication
> collected on the first call (saved in publication_tables_state). Its
> membership lookups (pg_publication_rel, pg_publication_namespace,
> ancestors etc) still read the current catalog, so a table that was
> really removed from the publication is still skipped, as 0003 intends;
> only the change of pub-setting is no longer confused as a removal of
> table.

Attached v5 which addresses the issue raised by Dilip.

v5-0001 and v5-0002: Unchanged.
V5-0003: Addresses the bug caused by 'publish_via_partition_root'
setting change.

thanks
Shveta

Attachment Content-Type Size
v5-0001-Fix-cache-lookup-failure-in-pg_get_publication_ta.patch application/octet-stream 8.9 KB
v5-0002-Do-not-return-wrong-column-list-and-row-filter-fo.patch application/octet-stream 2.5 KB
v5-0003-Skip-rows-for-tables-concurrently-removed-from-th.patch application/octet-stream 5.0 KB

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message Fujii Masao 2026-11-16 05:12:46 Re: Re: BUG #19776: pg_combinebackup ignores the truncation_block_length of an intermediate incremental backup
Previous Message shveta malik 2026-11-16 03:54:10 Re: BUG #19864: pg_get_publication_tables() gets cache lookup error after concurrent DROP PUBLICATION