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

From: Andrew Dunstan <andrew(at)dunslane(dot)net>
To: Zsolt Parragi <zsolt(dot)parragi(at)percona(dot)com>
Cc: pgsql-hackers(at)lists(dot)postgresql(dot)org, Álvaro Herrera <alvherre(at)kurilemu(dot)de>, Antonin Houska <ah(at)cybertec(dot)at>
Subject: Re: Table AM callback for logical decoding support (REPACK CONCURRENTLY)
Date: 2026-11-21 13:42:48
Message-ID: 969623fe-5a48-41cc-ab91-08fe15b228ae@dunslane.net
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers


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.

It's also another reason the RmgrId idea wouldn't have been enough:
knowing that a resource manager has an rm_decode tells us nothing about
whether it applies the filter.

>
>
> Also, the helper can crash with partitioned tables or views:
>
> CREATE TABLE p (i int PRIMARY KEY, j int) PARTITION BY RANGE (i);
> SELECT test_tableam_supports_features('p'::regclass, 1);
> server closed the connection unexpectedly
> LOG: client backend (PID 965976) was terminated by signal 11:
> Segmentation fault
> LOG: all server processes terminated; reinitializing

Thanks, I can reproduce that: a partitioned table or a view has no table AM,
so test_tableam_supports_features() dereferenced a NULL rd_tableam. 
It's only
the test helper, since REPACK checks the relkind first, but it was
wrong.  The
helper now rejects anything without a table AM ("is not a table"), and the
test module covers a partitioned table, a view and an index.  I also
added an
Assert on rd_tableam to table_relation_supports_features(), so misuse fails
clearly on an assert build; I didn't add a guard there, as the other table_*
wrappers don't have one.

v4 is attached.  It passes the regress, isolation, test_decoding and
injection_points suites.

cheers

andrew

--
Andrew Dunstan
EDB: https://www.enterprisedb.com

Attachment Content-Type Size
v4-0001-Add-a-table-AM-callback-to-report-supported-featu.patch text/x-patch 25.2 KB

In response to

Browse pgsql-hackers by date

  From Date Subject
Previous Message Andrey Borodin 2026-11-21 13:40:15 Re: Stop masking visibility information during WAL consistency checking