Re: row filtering for logical replication - Mailing list pgsql-hackers

From vignesh C
Subject Re: row filtering for logical replication
Date
Msg-id CALDaNm2bq-Zab3i5pvuA3UTxHvo3BqPwmgXbyznpw5vz4=fxpA@mail.gmail.com
Whole thread Raw
In response to Re: row filtering for logical replication  (Peter Smith <smithpb2250@gmail.com>)
Responses RE: row filtering for logical replication
Re: row filtering for logical replication
List pgsql-hackers
On Thu, Nov 18, 2021 at 7:04 AM Peter Smith <smithpb2250@gmail.com> wrote:
>
> PSA new set of v40* patches.

Few comments:
1) When a table is added to the publication, replica identity is
checked. But while modifying the publish action to include
delete/update, replica identity is not checked for the existing
tables. I felt it should be checked for the existing tables too.
@@ -315,6 +405,9 @@ publication_add_relation(Oid pubid, PublicationRelInfo *pri,

                /* Fix up collation information */
                assign_expr_collations(pstate, whereclause);
+
+               /* Validate the row-filter. */
+               rowfilter_expr_checker(pub, targetrel, whereclause);

postgres=# create publication pub1 for table t1 where ( c1 = 10);
ERROR:  cannot add relation "t1" to publication
DETAIL:  Row filter column "c1" is not part of the REPLICA IDENTITY

postgres=# create publication pub1 for table t1 where ( c1 = 10) with
(PUBLISH = INSERT);
CREATE PUBLICATION
postgres=# alter publication pub1 set (PUBLISH=DELETE);
ALTER PUBLICATION

2) Since the error message is because it publishes delete/update
operations, it should include publish delete/update in the error
message. Can we change the error message:
+               if (!bms_is_member(attnum -
FirstLowInvalidHeapAttributeNumber, context->bms_replident))
+               {
+                       const char *colname = get_attname(relid, attnum, false);
+
+                       ereport(ERROR,
+
(errcode(ERRCODE_INVALID_COLUMN_REFERENCE),
+                                       errmsg("cannot add relation
\"%s\" to publication",
+
RelationGetRelationName(context->rel)),
+                                       errdetail("Row filter column
\"%s\" is not part of the REPLICA IDENTITY",
+                                                         colname)));
+               }

To something like:
ereport(ERROR,
(errcode(ERRCODE_INVALID_COLUMN_REFERENCE),
errmsg("cannot add relation \"%s\" to publication because row filter
column \"%s\" does not have a replica identity and publishes
deletes/updates",
   RelationGetRelationName(context->rel), colname),
errhint("To enable deleting/updating from the table, set REPLICA
IDENTITY using ALTER TABLE")));

Regards,
Vignesh



pgsql-hackers by date:

Previous
From: Greg Nancarrow
Date:
Subject: Re: Failed transaction statistics to measure the logical replication progress
Next
From: Ilya Anfimov
Date:
Subject: Re: [RFC] ASOF Join