Re: Table AM callback for logical decoding support (REPACK CONCURRENTLY)

From: Antonin Houska <ah(at)cybertec(dot)at>
To: Andrew Dunstan <andrew(at)dunslane(dot)net>
Cc: Zsolt Parragi <zsolt(dot)parragi(at)percona(dot)com>, pgsql-hackers(at)lists(dot)postgresql(dot)org, alvherre(at)kurilemu(dot)de
Subject: Re: Table AM callback for logical decoding support (REPACK CONCURRENTLY)
Date: 2026-11-24 17:49:59
Message-ID: 57140.1795542599@chrudos
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Andrew Dunstan <andrew(at)dunslane(dot)net> wrote:

>
> On 2026-11-20 Fr 7:00 PM, Zsolt Parragi wrote:
> > + * TABLEAM_SUPPORTS_LOGICAL_DECODING: every change to the relation's rows can
> > + * be logically decoded, which needs the AM's resource manager to have an
> > + * rm_decode callback. REPACK (CONCURRENTLY) checks this, as it would
> > + * otherwise lose the changes made while it runs.
> >
> > Doesn't it also require filtering (change_useless_for_repack)?
>
>
> Yes, it does, and the comment should have said so.  pgrepack's change
> callback asserts that it only sees changes to the relation being rebuilt
> ("Changes of other relation should not have been decoded"), so an AM whose
> rm_decode doesn't call change_useless_for_repack() would trip that on an
> assert build, and on a non-assert build feed other tables' changes into the
> rewrite.  Our AM's rm_decode already does it for each kind of change, which
> is how I missed that the contract didn't mention it. I have added it to the
> comment on the flag and to tableam.sgml.

When we were working on REPACK (CONCURRENTLY), Alvaro pointed out that the
filtering might fit better into the plugin. We haven't done it in v19, but the
mention of change_useless_for_repack() in your patch reminds me that the
function call really does not fit perfectly into rm_decode() - the problem is
that rm_decode() is also called during logical replication, which does not
need the filtering.

Attached is a patch that adds a new filtering callback to the output
plugin. If it's what Alvaro meant, then I wonder if it makes sense to merge it
first. (In any case, I added a TODO comment referencing this thread, so that
your documentation and comments are updated if your patch lands in the tree
first.)

--
Antonin Houska
Web: https://www.cybertec-postgresql.com

Attachment Content-Type Size
0001-Introduce-an-output-plugin-callback-to-filter-change.patch.nocfbot application/mbox 16.8 KB

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Álvaro Herrera 2026-11-24 18:08:41 Re: Resetting snapshots during the first phase of [CREATE |RE]INDEX CONCURRENTLY
Previous Message Zsolt Parragi 2026-11-24 17:36:01 Prevent stack overflow in exprLocation while parsing long queries