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 1eiilo-0001Pl-A3 for pgsql-bugs@arkaria.postgresql.org; Mon, 05 Feb 2018 15:33:24 +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 1eiiln-0008HB-DT for pgsql-bugs@arkaria.postgresql.org; Mon, 05 Feb 2018 15:33:23 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1eiiln-0008H2-3U for pgsql-bugs@lists.postgresql.org; Mon, 05 Feb 2018 15:33:23 +0000 Received: from mail-wm0-x232.google.com ([2a00:1450:400c:c09::232]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1eiilj-0007Xh-L2 for pgsql-bugs@lists.postgresql.org; Mon, 05 Feb 2018 15:33:22 +0000 Received: by mail-wm0-x232.google.com with SMTP id 143so26854844wma.5 for ; Mon, 05 Feb 2018 07:33:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=2ndquadrant-com.20150623.gappssmtp.com; s=20150623; h=subject:to:references:from:cc:message-id:date:user-agent :mime-version:in-reply-to:content-language; bh=sjXQon/+/uAXXLDFcpMUS4XiBnXcdpk/NbLoequCPPM=; b=NYK/tPpvakQPoCyZPjGp2FURz+3iWnvwh2iJj3b37itOE7QtaplKmZUzPD41SjRkmS 2ohxhJs1QZJntDI0RmNvfZau8yhRoSf4ytrXiDroWR4N/k+I8kG+3PHMahwQGzAQJd9s mPRAS1ZBypO9Yer1XNrNt+QLIr89rbr+RBHE63YmEYjB2rP86ym86Fi9BnbPUnfh7GY0 AFNLvdICyITanespqemVtG33lsc8hyj1d9eGGG25nXauc2C02mo5YFEC24f3nFwCOk+V a1ohbemtlJgBk4n4sK4oE6TPCRE6VdLEcq81sePMC9Vw8MnIzQ1p0qRePtBJRALEr8t3 LdIA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:cc:message-id:date :user-agent:mime-version:in-reply-to:content-language; bh=sjXQon/+/uAXXLDFcpMUS4XiBnXcdpk/NbLoequCPPM=; b=UBKwuwWSjK77WtdW0Ay+Xu94kqYcSZ8rn1D/tyE3SEj1VN6Pn2e1othbwmt9gFRogS FJdxd8ieHhfG2lCatGOSstGMS+rpy4LtAxwdedk6ABwGHU/fHBaytUuGcMbC5H8X9Cz3 pi7yxsOd8Gd8D9vVUHtVJqn11fkSxBN5MaSeiHM12m/MjH/t2tSQjxCifX5AlT0DDj4z pYuiPSpflUObHPzwor4qczHcID5q0Jm7RAb76vDLClP1d8g+X0gOc9beInn2CC0mF0qL 4OMM8q+abwWxFjaBZatXkrCgod2XSSZEA9vhKKuu1nymTs49ikGzy5YDIUfwSFBmrJc/ tcwA== X-Gm-Message-State: AKwxyteLqNG0Gx/d3MxcT6lJvzaahxhRyTqU7IsgduW8CPBUUEV1KRyl A0kLd5yn7sW9hH3h/LMLzlzn5Q== X-Google-Smtp-Source: AH8x2267pUywGQIMAhpbhTwvAx3DHjIKVSpr5h0JkL9KBu5T65Wtiu9C3y64hnFG5fAnteG7BAAFLA== X-Received: by 10.28.236.157 with SMTP id h29mr39888919wmi.160.1517844796725; Mon, 05 Feb 2018 07:33:16 -0800 (PST) Received: from [192.168.0.106] (150.123.broadband11.iol.cz. [90.178.123.150]) by smtp.gmail.com with ESMTPSA id m1sm4580387wrb.78.2018.02.05.07.33.15 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 05 Feb 2018 07:33:15 -0800 (PST) Subject: Re: BUG #15044: materialized views incompatibility with logical replication in postgres 10 To: Chad Trabant , "David G. Johnston" , pgsql-bugs@lists.postgresql.org References: <151753299917.1235.5710750500940066850@wrigleys.postgresql.org> <161542b1c98.27af.478e5036e088b5aaf247fa13bcb9f071@iris.washington.edu> From: Petr Jelinek Cc: Peter Eisentraut Message-ID: <5754c88e-0ea5-ee34-5b4b-e50a6c66822f@2ndquadrant.com> Date: Mon, 5 Feb 2018 16:33:14 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.6.0 MIME-Version: 1.0 In-Reply-To: <161542b1c98.27af.478e5036e088b5aaf247fa13bcb9f071@iris.washington.edu> Content-Type: multipart/mixed; boundary="------------4127E79361375F47D4BAB418" 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. --------------4127E79361375F47D4BAB418 Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 8bit Hi, On 02/02/18 02:39, Chad Trabant wrote: > On February 1, 2018 17:16:08 "David G. Johnston" > wrote: >>> Bug reference:      15044 >> >> It seems the work-around is to not use "for all tables" in your > publication >> definition. > > > Indeed.  My real world case 700+ tables with semi regular additions and > two materialized views so ALL TABLES was the right fit. > > >> As described it does seem bugged.  The table matview itself is not being >> published, as documented, but knowledge of its existence as part of the >> publication is... > > > 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. The attached patch should fix it (CCing to PeterE as the original committer). -- Petr Jelinek http://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Training & Services --------------4127E79361375F47D4BAB418 Content-Type: text/x-patch; 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 4272e15faefadc692e89ba06dcde64f07f4e075f Mon Sep 17 00:00:00 2001 From: Petr Jelinek Date: Mon, 5 Feb 2018 16:09:37 +0100 Subject: [PATCH] Fix filtering of unsupported relations in pgoutput For normal publications this was already handled when such relation was requested to be added to given publication by user. However the alltables publications don't use relation membership check so we have to handle filtering of unsupported relation kinds directly in pgoutput. --- src/backend/replication/pgoutput/pgoutput.c | 33 ++++++++++++++++++-----= ------ 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/src/backend/replication/pgoutput/pgoutput.c b/src/backend/re= plication/pgoutput/pgoutput.c index 40a1ef3c1d..37756474b9 100644 --- a/src/backend/replication/pgoutput/pgoutput.c +++ b/src/backend/replication/pgoutput/pgoutput.c @@ -509,15 +509,16 @@ get_rel_sync_entry(PGOutputData *data, Oid relid) Publication *pub =3D lfirst(lc); =20 /* - * Skip tables that look like they are from a heap rewrite (see - * make_new_heap()). We need to skip them because the subscriber - * won't have a table by that name to receive the data. That - * means we won't ship the new data in, say, an added column with - * a DEFAULT, but if the user applies the same DDL manually on the - * subscriber, then this will work out for them. + * We might see changes here from relations which we don't know + * how to handle correcly, hence we have to filter them out. * - * We only need to consider the alltables case, because such a - * transient heap won't be an explicit member of a publication. + * These include: + * a) materialized views + * b) temporary relations used for heap rewrite + * + * We only care about those in alltables publications because + * for normal publications they will fail membership test. Also + * see check_publication_add_relation(). */ if (pub->alltables) { @@ -525,12 +526,20 @@ get_rel_sync_entry(PGOutputData *data, Oid relid) unsigned int u; int n; =20 + /* + * We don't allow publishing of anything that's not a + * relation. + */ + if (get_rel_relkind(relid) !=3D RELKIND_RELATION) + break; + + /* + * We also don't allow publishing temporary heaps for relation + * rewrite. See make_new_heap(). + */ if (sscanf(relname, "pg_temp_%u%n", &u, &n) =3D=3D 1 && relname[n] =3D=3D '\0') - { - if (get_rel_relkind(u) =3D=3D RELKIND_RELATION) - break; - } + break; } =20 if (pub->alltables || list_member_oid(pubids, pub->oid)) --=20 2.14.1 --------------4127E79361375F47D4BAB418--