Hi, While browsing the logical replication code, I noticed two issues.
1. Apply worker reports the partitioned table instead of the leaf partition in some errors When an UPDATE or DELETE is routed to a leaf partition on the subscriber, apply_handle_tuple_routing() calls check_relation_updatable() on the partition's map entry. The entry's updatable and idxisreplident fields are computed from the leaf partition (logicalrep_partition_open() -> logicalrep_rel_mark_updatable() and FindLogicalRepLocalIndex(partrel, ...)), but both error messages print rel->remoterel.nspname/relname, which logicalrep_partition_open() copies from the root. So the error names the partitioned table, not the partition that failed the check. One could argue that is acceptable, since a primary key on the partitioned table would have avoided the error. But REPLICA IDENTITY is not inherited by partitions, so the message can be plainly false: -- publisher CREATE TABLE tab (a int PRIMARY KEY, b int); CREATE PUBLICATION pub FOR TABLE tab; -- subscriber CREATE TABLE tab (a int NOT NULL, b int) PARTITION BY RANGE (a); CREATE UNIQUE INDEX tab_a_idx ON tab (a); ALTER TABLE tab REPLICA IDENTITY USING INDEX tab_a_idx; CREATE TABLE tab_p1 PARTITION OF tab FOR VALUES FROM (0) TO (100); CREATE SUBSCRIPTION sub CONNECTION '...' PUBLICATION pub; -- publisher INSERT INTO tab VALUES (1, 0); UPDATE tab SET b = 1 WHERE a = 1; The subscriber logs: ERROR: logical replication target relation "public.tab" has neither REPLICA IDENTITY index nor PRIMARY KEY and published relation does not have REPLICA IDENTITY FULL public.tab does have a REPLICA IDENTITY index; it is tab_p1 that has neither. The other message, "publisher did not send replica identity column expected by the logical replication target relation", has the same problem, and there the replica identity index it refers to exists only on the leaf partition. Nothing in the output names tab_p1, since the error context also prints the remote relation name. CheckSubscriptionTargetRel(), called a few lines earlier for the same routed tuple, already reports the partition. 0001 reports the local relation in both messages. For tables that are not reached through tuple routing, the local and remote names are the same, so those messages are unchanged. For partitions, the error context still names the partitioned table, so both names now appear. The patch extends 013_partition.pl, next to the existing test for the opposite case (the leaf partition has a replica identity, the partitioned table does not). The code is the same in all supported branches, so I think this should be back-patched. 2. Missing RelationClose() in check_and_init_gencol() check_and_init_gencol() in pgoutput.c gets the relation with RelationIdGetRelation() but never calls RelationClose(), on either return path. Its sibling pgoutput_column_list_init() does close it. There is no visible symptom, because decoding always aborts the transaction this runs in and leaked relcache references are released silently on abort, but it is still a reference leak. 0002 adds the missing calls. This function exists from PG 18. The two patches are independent of each other. Regards, Ajin Cherian Fujitsu Australia
v1-0001-Report-the-leaf-partition-in-apply-worker-errors.patch
Description: Binary data
v1-0002-Close-the-relation-opened-in-check_and_init_genco.patch
Description: Binary data
