Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1tZ4fw-000Qp8-W5 for pgsql-hackers@arkaria.postgresql.org; Sat, 18 Jan 2025 08:59:30 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1tZ4fv-00GfRd-Ji for pgsql-hackers@arkaria.postgresql.org; Sat, 18 Jan 2025 08:59:28 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1tZ4fv-00GfRA-0O for pgsql-hackers@lists.postgresql.org; Sat, 18 Jan 2025 08:59:27 +0000 Received: from mail.postgrespro.ru ([93.174.131.139]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1tZ4fr-000AlX-2F for pgsql-hackers@lists.postgresql.org; Sat, 18 Jan 2025 08:59:26 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=postgrespro.ru; s=mx2023; t=1737190760; bh=XwTUk65CYVLDy43DsYkcLE1+5i76Du1eLj8UX/iHlD4=; h=Message-ID:Date:User-Agent:Subject:To:Cc:References:From: In-Reply-To:From; b=EhHirOX4BuEPGWDEGOTlaPnLPd2xR3uIZPsnYimgCZBrSpfylNN50rujAVB8yaTVb +v/3PQXSbv+Tq5tzC0W6ZHIuoT/tFHxn/5Y/I/ov79ekj9L0l2kBmZA1VyBmjGQaqm AJn4M+NkjolJMTK5HGwb+2ComUySp8+fOM7D8z2lznTh36un4pwykulG/rR0Cd9ugD GUwY6lKRUC2L1X09TULwMXw8kwAdI5ET7YnXiGtP0MV4Rr028SSJRWIhCCnvS8pawt aAwAsR5xamQjiHcnMD1Al3vePsEUcxKVK2LrGQ6vMn4jCOmoes8FhAWVsHAo2vaeie rtnEFDUp/ynjw== Received: from [192.168.129.193] (unknown [89.113.138.106]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (Client did not present a certificate) (Authenticated sender: s.tatarintsev@postgrespro.ru) by mail.postgrespro.ru (Postfix/465) with ESMTPSA id A63E060AA7; Sat, 18 Jan 2025 11:59:19 +0300 (MSK) Content-Type: multipart/alternative; boundary="------------80Du5Lw2tAcE0BoFEG6mm3vX" Message-ID: <8e06e68c-db9d-4fdf-82ae-0ac0861d5e18@postgrespro.ru> Date: Sat, 18 Jan 2025 15:59:17 +0700 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: create subscription with (origin = none, copy_data = on) To: vignesh C Cc: pgsql-hackers@lists.postgresql.org References: <5eda6a9c-63cf-404d-8a49-8dcb116a29f3@postgrespro.ru> Content-Language: en-US From: Sergey Tatarintsev In-Reply-To: X-KSMG-AntiPhishing: NotDetected, bases: 2025/01/18 07:42:00 X-KSMG-AntiSpam-Interceptor-Info: not scanned X-KSMG-AntiSpam-Status: not scanned, disabled by settings X-KSMG-AntiVirus: Kaspersky Secure Mail Gateway, version 2.1.0.7854, bases: 2025/01/18 08:11:00 #27058329 X-KSMG-AntiVirus-Status: NotDetected, skipped X-KSMG-LinksScanning: not scanned, disabled by settings X-KSMG-Message-Action: skipped X-KSMG-Rule-ID: 1 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk This is a multi-part message in MIME format. --------------80Du5Lw2tAcE0BoFEG6mm3vX Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit 18.01.2025 12:01, vignesh C пишет: > On Fri, 17 Jan 2025 at 21:30, vignesh C wrote: >> On Fri, 17 Jan 2025 at 14:00, Sergey Tatarintsev >> wrote: >>> Hi, hackers! >>> >>> I am looking at subscription creation command: >>> >>> CREATE SUBSCRIPTION sub CONNECTION '...' PUBLICATION pub WITH (origin = >>> none, copy_data = on); >>> >>> For now we log a warning if the publisher has subscribed to the same >>> table from some other publisher. >>> However, in case of publication with publish_via_partition_root option, >>> we will not raise such warinigs >>> because SQL command in check_publications_origin() checks only directly >>> published tables. >> Yes, I agree that we are checking only the directly published tables >> which is why there is no warning in this case. I'm working on a fix to >> change the check_publications_origin to check accordingly. > Attached patch has the fix for this issue which includes the partition > tables also for the publication now and throws a warning > appropriately. > > Regards, > Vignesh Thanks for patch! I think we must take into account whole inheritance tree of partitioned table. For example: node_A: CREATE TABLE t(id int); CREATE PUBLICATION pub_b FOR TABLE t; node_A: CREATE TABLE t(id int) PARTITION BY RANGE(id); CREATE TABLE part PARTITION OF t FOR VALUES FROM (0) TO (10) PARTITION BY RANGE(id); CREATE TABLE subpart PARTITION OF part FOR VALUES FROM (0) TO (5); CREATE SUBSCRIPTION sub_c CONNECTION '$node_B_connstr' PUBLICATION pub_b; CREATE PUBLICATION pub_t FOR TABLE t WITH (publish_via_partition_root); CREATE PUBLICATION pub_part FOR TABLE part WITH (publish_via_partition_root); node_C: -- this command will raise a warning CREATE SUBSCRIPTION sub_t CONNECTION '$node_A_connstr' PUBLICATION pub_t WITH (origin = none, copy_data = on); DROP SUBSCRIPTION IF EXISTS sub_t; -- here we got silence, but "part" is in tree of upper level replicated table CREATE SUBSCRIPTION sub_part CONNECTION '$node_A_connstr' PUBLICATION pub_part WITH (origin = none, copy_data = on); DROP SUBSCRIPTION IF EXISTS sub_part; I think that for each partition/partitioned table in the publication we can use something like select relid from pg_partition_tree('part'::regclass) union select relid from pg_partition_ancestors('part'::regclass); In this case  we don't care about  publish_via_partition_root option, because we already check all inheritance tree, and there is no need to change pg_class What are you thinking about it? --------------80Du5Lw2tAcE0BoFEG6mm3vX Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 8bit


18.01.2025 12:01, vignesh C пишет:
On Fri, 17 Jan 2025 at 21:30, vignesh C <vignesh21@gmail.com> wrote:
On Fri, 17 Jan 2025 at 14:00, Sergey Tatarintsev
<s.tatarintsev@postgrespro.ru> wrote:
Hi, hackers!

I am looking at subscription creation command:

CREATE SUBSCRIPTION sub CONNECTION '...' PUBLICATION pub WITH (origin =
none, copy_data = on);

For now we log a warning if the publisher has subscribed to the same
table from some other publisher.
However, in case of publication with publish_via_partition_root option,
we will not raise such warinigs
because SQL command in check_publications_origin() checks only directly
published tables.
Yes, I agree that we are checking only the directly published tables
which is why there is no warning in this case. I'm working on a fix to
change the check_publications_origin to check accordingly.
Attached patch has the fix for this issue which includes the partition
tables also for the publication now and throws a warning
appropriately.

Regards,
Vignesh

Thanks for patch!

I think we must take into account whole inheritance tree of partitioned table.

For example:

node_A:
CREATE TABLE t(id int);
CREATE PUBLICATION pub_b FOR TABLE t;

node_A:
CREATE TABLE t(id int) PARTITION BY RANGE(id);
CREATE TABLE part PARTITION OF t FOR VALUES FROM (0) TO (10) PARTITION BY RANGE(id);
CREATE TABLE subpart PARTITION OF part FOR VALUES FROM (0) TO (5);
CREATE SUBSCRIPTION sub_c CONNECTION '$node_B_connstr' PUBLICATION pub_b;
CREATE PUBLICATION pub_t FOR TABLE t WITH (publish_via_partition_root);
CREATE PUBLICATION pub_part FOR TABLE part WITH (publish_via_partition_root);

node_C:
-- this command will raise a warning CREATE SUBSCRIPTION sub_t CONNECTION '$node_A_connstr' PUBLICATION pub_t WITH (origin = none, copy_data = on);
DROP SUBSCRIPTION IF EXISTS sub_t;
-- here we got silence, but "part" is in tree of upper level replicated table
CREATE SUBSCRIPTION sub_part CONNECTION '$node_A_connstr' PUBLICATION pub_part WITH (origin = none, copy_data = on);
DROP SUBSCRIPTION IF EXISTS sub_part;

I think that for each partition/partitioned table in the publication we can use something like

select relid from pg_partition_tree('part'::regclass)
union
select relid from pg_partition_ancestors('part'::regclass);

In this case  we don't care about  publish_via_partition_root option, because we already check all inheritance tree, and there is no need to change pg_class

What are you thinking about it?

 

--------------80Du5Lw2tAcE0BoFEG6mm3vX--