Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1enFtJ-0006pS-KR for pgsql-bugs@arkaria.postgresql.org; Sun, 18 Feb 2018 03:43:53 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1enFtG-0001t9-VL for pgsql-bugs@arkaria.postgresql.org; Sun, 18 Feb 2018 03:43:50 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1enFtG-0001sz-EE for pgsql-bugs@lists.postgresql.org; Sun, 18 Feb 2018 03:43:50 +0000 Received: from out5-smtp.messagingengine.com ([66.111.4.29]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1enFt7-0007Uq-4v for pgsql-bugs@lists.postgresql.org; Sun, 18 Feb 2018 03:43:48 +0000 Received: from compute7.internal (compute7.nyi.internal [10.202.2.47]) by mailout.nyi.internal (Postfix) with ESMTP id EB15320CB2; Sat, 17 Feb 2018 22:43:39 -0500 (EST) Received: from frontend1 ([10.202.2.160]) by compute7.internal (MEProxy); Sat, 17 Feb 2018 22:43:39 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-sender :x-me-sender:x-sasl-enc; s=fm2; bh=sGMP/0mHypYcPlOedv2t0vTeloMPC 9X/9JSKkKopsAs=; b=OZlNMFKMgH30/UGymTYN9ixRxUhPfhEv8yrgUyDDp0Acm eKUXa7byu4+ZXAowDd0zdCaY6oWeqbU80Lu+afXaEwqTjxEixW6lqSVuBTqWo7R8 FjWK7GHv1oxrIfKBDV4Y9uDq9e52OA8KCBhShRA6xjKXXxC5AjNSI+YyDw3KIOSz MEr5LY38aBrDb3cEjsSEVwj3LgZSfIKi/Yky7xZbgGp09TOWFwzOM2B4XSz3R9/k MtbQoON/Q2E1tLuxRZGAp3cPtBvisWEZX7EQ+8dWb4IaIoBV2lXtVvPxfLpWnT3K BzvbL7/LpfdrsUjaCpcR11Ne8gSTMgY/csLC0gqng== X-ME-Sender: Received: from april.local (c-73-13-66-39.hsd1.pa.comcast.net [73.13.66.39]) by mail.messagingengine.com (Postfix) with ESMTPA id 9922B7E321; Sat, 17 Feb 2018 22:43:39 -0500 (EST) Subject: Re: BUG #15044: materialized views incompatibility with logical replication in postgres 10 To: Petr Jelinek , Chad Trabant , "David G. Johnston" , pgsql-bugs@lists.postgresql.org References: <151753299917.1235.5710750500940066850@wrigleys.postgresql.org> <161542b1c98.27af.478e5036e088b5aaf247fa13bcb9f071@iris.washington.edu> <5754c88e-0ea5-ee34-5b4b-e50a6c66822f@2ndquadrant.com> From: Peter Eisentraut Organization: 2ndQuadrant Message-ID: <6e375316-91a4-7825-ef8b-9b8915ab6980@2ndquadrant.com> Date: Sat, 17 Feb 2018 22:43:38 -0500 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.13; rv:52.0) Gecko/20100101 Thunderbird/52.6.0 MIME-Version: 1.0 In-Reply-To: <5754c88e-0ea5-ee34-5b4b-e50a6c66822f@2ndquadrant.com> Content-Type: multipart/mixed; boundary="------------952BACE98D4C8CE41D01917A" Content-Language: en-US List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk This is a multi-part message in MIME format. --------------952BACE98D4C8CE41D01917A Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 8bit On 2/5/18 10:33, Petr Jelinek wrote: >> Exactly.  The matview does not show up in pg_publication_tables but it's >> registered at some level. > > Indeed this is a bug. For normal publications we take care of this when > adding the relation to the publication but since ALL TABLES publications > don't check for membership we have to filter this directly in the output > plugin. I think the filtering in pgoutput ought to make use of is_publishable_class() in some way. That takes care of non-tables such as materialized views, but it also filters out the information_schema tables for example. Right now, if you insert something into one of the IS tables, it gets shipped over the wire but is then dropped by the apply because there is no pg_subscription_rel entry of the table. That doesn't quite have the user-visible effect as this bug, but it's bogus nonetheless. So I propose this alternative patch that covers all these cases. -- Peter Eisentraut http://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services --------------952BACE98D4C8CE41D01917A Content-Type: text/plain; charset=UTF-8; x-mac-type="0"; x-mac-creator="0"; name="0001-Fix-filtering-of-unsupported-relations-in-pgoutput.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename*0="0001-Fix-filtering-of-unsupported-relations-in-pgoutput.patc"; filename*1="h" =46rom fb9ad748f903e0e67b173022f3fd39b0a82034ba Mon Sep 17 00:00:00 2001 From: Peter Eisentraut Date: Sat, 17 Feb 2018 22:30:18 -0500 Subject: [PATCH] Fix filtering of unsupported relations in pgoutput Bug: #15044 --- src/backend/catalog/pg_publication.c | 9 +++++++++ src/backend/replication/pgoutput/pgoutput.c | 3 +++ src/include/catalog/pg_publication.h | 1 + 3 files changed, 13 insertions(+) diff --git a/src/backend/catalog/pg_publication.c b/src/backend/catalog/p= g_publication.c index 3ef7ba8cd5..a0973f43e2 100644 --- a/src/backend/catalog/pg_publication.c +++ b/src/backend/catalog/pg_publication.c @@ -105,6 +105,15 @@ is_publishable_class(Oid relid, Form_pg_class reltup= le) relid >=3D FirstNormalObjectId; } =20 +/* + * Another variant of this, taking a Relation. + */ +bool +is_publishable_relation(Relation rel) +{ + return is_publishable_class(RelationGetRelid(rel), rel->rd_rel); +} + =20 /* * SQL-callable variant of the above diff --git a/src/backend/replication/pgoutput/pgoutput.c b/src/backend/re= plication/pgoutput/pgoutput.c index 61e53aba19..38b0eab7d2 100644 --- a/src/backend/replication/pgoutput/pgoutput.c +++ b/src/backend/replication/pgoutput/pgoutput.c @@ -264,6 +264,9 @@ pgoutput_change(LogicalDecodingContext *ctx, ReorderB= ufferTXN *txn, MemoryContext old; RelationSyncEntry *relentry; =20 + if (!is_publishable_relation(relation)) + return; + relentry =3D get_rel_sync_entry(data, RelationGetRelid(relation)); =20 /* First check the table filter */ diff --git a/src/include/catalog/pg_publication.h b/src/include/catalog/p= g_publication.h index aa148960cd..be4987505d 100644 --- a/src/include/catalog/pg_publication.h +++ b/src/include/catalog/pg_publication.h @@ -93,6 +93,7 @@ extern List *GetPublicationRelations(Oid pubid); extern List *GetAllTablesPublications(void); extern List *GetAllTablesPublicationRelations(void); =20 +extern bool is_publishable_relation(Relation rel); extern ObjectAddress publication_add_relation(Oid pubid, Relation target= rel, bool if_not_exists); =20 --=20 2.16.1 --------------952BACE98D4C8CE41D01917A--