]> granicus.if.org Git - postgresql/commitdiff
Fix filtering of unsupported relations in logical replication
authorPeter Eisentraut <peter_e@gmx.net>
Sat, 24 Feb 2018 02:17:57 +0000 (21:17 -0500)
committerPeter Eisentraut <peter_e@gmx.net>
Sat, 24 Feb 2018 03:09:26 +0000 (22:09 -0500)
In the pgoutput plugin, skip changes for relations that are not
publishable, per is_publishable_class().  This concerns in particular
materialized views and information_schema tables.  While those relations
cannot be part of a publication, per existing checks, they will be
considered by a FOR ALL TABLES publication.  A subscription would not
actually apply changes for those relations, again per existing checks,
but trying to match incoming changes to local tables on the subscriber
would lead to errors if no matching local table exists.  Skipping those
changes on the publisher avoids sending useless changes and eliminates
the error.

Bug: #15044
Reported-by: Chad Trabant <chad@iris.washington.edu>
Reviewed-by: Petr Jelinek <petr.jelinek@2ndquadrant.com>
src/backend/catalog/pg_publication.c
src/backend/replication/pgoutput/pgoutput.c
src/include/catalog/pg_publication.h

index 3ef7ba8cd5528dfe06c42a5623bd56836d891d9d..a0973f43e279d9fdfd673cfdd1b9382fca29fba5 100644 (file)
@@ -105,6 +105,15 @@ is_publishable_class(Oid relid, Form_pg_class reltuple)
                relid >= FirstNormalObjectId;
 }
 
+/*
+ * Another variant of this, taking a Relation.
+ */
+bool
+is_publishable_relation(Relation rel)
+{
+       return is_publishable_class(RelationGetRelid(rel), rel->rd_rel);
+}
+
 
 /*
  * SQL-callable variant of the above
index 61e53aba193effae3ae687b54b3bb81265df9c3c..38b0eab7d2e2be7f421fb9284457de12ee356595 100644 (file)
@@ -264,6 +264,9 @@ pgoutput_change(LogicalDecodingContext *ctx, ReorderBufferTXN *txn,
        MemoryContext old;
        RelationSyncEntry *relentry;
 
+       if (!is_publishable_relation(relation))
+               return;
+
        relentry = get_rel_sync_entry(data, RelationGetRelid(relation));
 
        /* First check the table filter */
index aa148960cd985f4356a291e0cde4351a73cd67cd..be4987505d8caa4b5d6851cb149f2dbe228de26d 100644 (file)
@@ -93,6 +93,7 @@ extern List *GetPublicationRelations(Oid pubid);
 extern List *GetAllTablesPublications(void);
 extern List *GetAllTablesPublicationRelations(void);
 
+extern bool is_publishable_relation(Relation rel);
 extern ObjectAddress publication_add_relation(Oid pubid, Relation targetrel,
                                                 bool if_not_exists);