Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iJNbT-0006f7-JJ for pgsql-hackers@arkaria.postgresql.org; Sat, 12 Oct 2019 20:03:04 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1iJNaU-0003AX-7N for pgsql-hackers@arkaria.postgresql.org; Sat, 12 Oct 2019 20:02:02 +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_SHA1:256) (Exim 4.89) (envelope-from ) id 1iJNaT-0003AM-Qo for pgsql-hackers@lists.postgresql.org; Sat, 12 Oct 2019 20:02:01 +0000 Received: from mail-wr1-x434.google.com ([2a00:1450:4864:20::434]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iJNaQ-00051R-RX for pgsql-hackers@postgresql.org; Sat, 12 Oct 2019 20:02:01 +0000 Received: by mail-wr1-x434.google.com with SMTP id o18so15300622wrv.13 for ; Sat, 12 Oct 2019 13:01:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=2ndquadrant-com.20150623.gappssmtp.com; s=20150623; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-language:content-transfer-encoding; bh=+n2dTIkrGjUCgQMWmpYwvA6vJkZrhVYifjF5LGtIFM4=; b=wOsoLgPu9Irgmwc2X1egf2kgK86wIlF3GzpKjv8kp6MAhBqYGk3kbl39pxvaUHV1HZ S4N8P3MJEh0oOHDOkM7DRitv75pAdHo+KaVbgpNhM9rduu0Rwe9f//vHhybMeApuWEQB gNjV5ZGILjzywR5NdZhHscLs+rjI4Plv1goxMR+vyQdQ0fNwLsFHR7leUGeo5H7qGUSw kw9msru3aRGIDa9RAv1Pasgo2VRIKc5m6al8kzy5osumTSaPf8pMNtrTZkel+XYEWpE5 nefn2L0QNtX32DiRHAq4MDj9JC5ak+Z6Mw3sk+1GR0Xr/vls5m8ZJqh77C66EA8ZYxcy NGfQ== 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:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=+n2dTIkrGjUCgQMWmpYwvA6vJkZrhVYifjF5LGtIFM4=; b=uHeY2wrfYEouOrWFja2cj23zOHGvi0E8Qg52gKcuW1hnzvST5yHVNvSUgCc2/KWnmV 7AncC1fO4KTTN9vH4xsi3pk1KqfRiUqml5CD9xG3QrY1p8vjjw+5FIKpgv5pH5hMfTya dTMiOeHwUbC4xc8fbZVkQ4SDmUev1HgpkJlNfT06r8UeP5xC2XQfEBm66sTFiyKt4eSF 3q2kHWNXROQHOEW8lZUA12F4MoRCif9wxUSjo5oaNfqmjLn175Z+DnScXZ9s6jOlW3FD KcuKQ/31B7jn0vCJ4OuDM5xPo1P+yhABnB/fjs/7eEcMHjuZ35VHBYS1vWkSm3Qji0vy y/Gg== X-Gm-Message-State: APjAAAW1BTazvAvKvb4WxFvChZqIsa8k5RODU3b+KTVbGTPhJXA442DX w1b3CxbBp/oj0wx+17rQJoArIP5CfcY4kGW8QW4CkJEDCHQi/erHWXJEsJ3y5gZWibLtV6dczP4 C7Bd5qITZ8WwChQAOrIl1CEtAdgwJMkXPQZZnJ/ttQNI7MbCg2QNVL3/3X6I1EPhU5DGr2l9j8h 5d X-Google-Smtp-Source: APXvYqw/a/oEc8G4IFGQ8jYz2IFPXbIR/1SH59i5CNh+ozl3PKzXRmAN/5c5OdRZiuBJyI4e5fhlZg== X-Received: by 2002:adf:b102:: with SMTP id l2mr19918559wra.269.1570910516578; Sat, 12 Oct 2019 13:01:56 -0700 (PDT) Received: from ?IPv6:2a02:8308:13b:9400:54a1:714f:b878:5d89? ([2a02:8308:13b:9400:54a1:714f:b878:5d89]) by smtp.gmail.com with ESMTPSA id q10sm24792532wrd.39.2019.10.12.13.01.55 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 12 Oct 2019 13:01:55 -0700 (PDT) Subject: Re: adding partitioned tables to publications To: Amit Langote , PostgreSQL-development References: From: Petr Jelinek Message-ID: Date: Sat, 12 Oct 2019 22:01:55 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.9.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Hi, On 07/10/2019 02:55, Amit Langote wrote: > One cannot currently add partitioned tables to a publication. > > create table p (a int, b int) partition by hash (a); > create table p1 partition of p for values with (modulus 3, remainder 0); > create table p2 partition of p for values with (modulus 3, remainder 1); > create table p3 partition of p for values with (modulus 3, remainder 2); > > create publication publish_p for table p; > ERROR: "p" is a partitioned table > DETAIL: Adding partitioned tables to publications is not supported. > HINT: You can add the table partitions individually. > > One can do this instead: > > create publication publish_p1 for table p1; > create publication publish_p2 for table p2; > create publication publish_p3 for table p3; Or just create publication publish_p for table p1, p2, p3; > > but maybe that's too much code to maintain for users. > > I propose that we make this command: > > create publication publish_p for table p; > +1 > automatically add all the partitions to the publication. Also, any > future partitions should also be automatically added to the > publication. So, publishing a partitioned table automatically > publishes all of its existing and future partitions. Attached patch > implements that. > > What doesn't change with this patch is that the partitions on the > subscription side still have to match one-to-one with the partitions > on the publication side, because the changes are still replicated as > being made to the individual partitions, not as the changes to the > root partitioned table. It might be useful to implement that > functionality on the publication side, because it allows users to > define the replication target any way they need to, but this patch > doesn't implement that. > Yeah for that to work subscription would need to also need to be able to write to partitioned tables, so it needs both sides to add support for this. I think if we do both what you did and the transparent handling of root only, we'll need new keyword to differentiate the two. It might make sense to think about if we want your way to need an extra keyword or the transparent one will need it. One issue that I see reading the patch is following set of commands: CREATE TABLE foo ...; CREATE PUBLICATION mypub FOR TABLE foo; CREATE TABLE bar ...; ALTER PUBLICATION mypub ADD TABLE bar; ALTER TABLE foo ATTACH PARTITION bar ...; ALTER TABLE foo DETACH PARTITION bar ...; This will end up with bar not being in any publication even though it was explicitly added. That might be acceptable caveat but it at least should be clearly documented (IMHO with warning). -- Petr Jelinek 2ndQuadrant - PostgreSQL Solutions for the Enterprise https://www.2ndQuadrant.com/