Hi, While testing publication DDLs, I noticed an unexpected behavior where the MERGE command can be executed on tables lacking replica identity keys, regardless of whether they are part of a publication that publishes updates and deletes.
Replication and application of the updates and deletes generated by MERGE command require replica identity keys in the WAL record, which are essential for the apply worker on the subscriber to find local tuples for updating or deletion. Furthermore, publications require specific columns to be part of the replica identity key if the table specifies a publication row filter or column list. We already have restrictions on executing UPDATE and DELETE commands for tables without replica identity keys under similar conditions. So, I think the same restriction should apply to the MERGE command as well. Attached is a patch that implements this fix. I have confirmed that this issue has existed since the introduction of the MERGE command in PG15. Best Regards, Hou zj
v1-0001-Fix-replica-identity-check-for-MERGE-command.patch
Description: v1-0001-Fix-replica-identity-check-for-MERGE-command.patch