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 1tYzCk-00HAPt-0h for pgsql-hackers@arkaria.postgresql.org; Sat, 18 Jan 2025 03:08:59 +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 1tYzCg-00C5Ws-Jr for pgsql-hackers@arkaria.postgresql.org; Sat, 18 Jan 2025 03:08:55 +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 1tYzCg-00C5Wk-4m for pgsql-hackers@lists.postgresql.org; Sat, 18 Jan 2025 03:08:54 +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 1tYzCd-0008Ev-07 for pgsql-hackers@lists.postgresql.org; Sat, 18 Jan 2025 03:08:53 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=postgrespro.ru; s=mx2023; t=1737169727; bh=UXr2/2Hr7aVMZRKSzsQckCy1uBmrH0sVJFpgJubnHeg=; h=Message-ID:Date:User-Agent:Subject:To:Cc:References:From: In-Reply-To:From; b=zXxuzbxqjgjc0qq4OjsGMNRHcLQ3uoGy4HtVWarb3l3EQrmp8vhTKm/nEN46QEg/L 583QN29grh/whfbKpABckAgiD/fl1JZqO3kM/aIf4D1kaAVNjHwHzqjwWJdx/MEVi6 oAf7zr1OtE3aoDNvNGDEGmIqfB+v6cfA2atuU4xzzIiEMeJv0P3qMfBcBDTJKgBRGT 8SdLvtnP13+Kfvf2wol/KXS0cy5xr66ipagNXxs116HxIBHNeAUgJpR0kQrRGxT2OG sXczxGn5xDxymvd8YUrE7VIOtG2nPnTkDEjoawK8OwM34Z2Zams05/2ICxocACip9J +alRFZh0p24Xw== 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 7C21160B24; Sat, 18 Jan 2025 06:08:46 +0300 (MSK) Message-ID: <3a979823-3b3a-4c05-a3fd-3b2bf236ac54@postgrespro.ru> Date: Sat, 18 Jan 2025 10:08:43 +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: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-KSMG-AntiPhishing: NotDetected, bases: 2025/01/18 02:17: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 00:34:00 #27053442 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 17.01.2025 23:00, vignesh C пишет: > 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. seems promising. I would like to see this patch >> For example: >> >> CREATE TABLE t(id int) PARTITION BY RANGE(id); >> CREATE TABLE part1 PARTITION OF t FOR VALUES FROM (0) TO (5); >> CREATE TABLE part2 PARTITION OF t FOR VALUES FROM (5) TO (10); >> -- subscribe to part2 >> CREATE SUBSCRIPTION sub_part2 CONNECTION '...' PUBLICATION pub_part2; >> CREATE PUBLICATION pub_t FOR TABLE t; >> CREATE PUBLICATION pub_t_via_root FOR TABLE t WITH >> (publish_via_partition_root); >> >> and now this command will raise a warning: >> CREATE SUBSCRIPTION sub1 CONNECTION '...' PUBLICATION pub_t WITH (origin >> = none, copy_data = on); >> >> but not this: >> CREATE SUBSCRIPTION sub1 CONNECTION '...' PUBLICATION pub_t_via_root >> WITH (origin = none, copy_data = on); >> >> We also do not take into account cases of foreign partitions: >> CREATE TABLE t(id int) PARTITION BY RANGE(id); >> CREATE TABLE part1 PARTITION OF t FOR VALUES FROM (0) TO (5); >> CREATE FOREIGN TABLE part2 PARTITION OF t FOR VALUES FROM (5) TO (10) >> SERVER fdw_server; >> CREATE PUBLICATION pub_t FOR TABLE t; >> >> Maybe we should raise WARNING (or even ERROR) in such cases? > Currently we do not support replication of foreign tables. This is > mentioned in logical replication restriction sections at [1]. Yes of course, but we must raise an ERROR in such cases >> I would also note that the (origin = none) will work as expected, but in >> case of (origin = any) >> it will lead to inappropriate behavior - we will perform an initial sync >> of "t", but we unable to >> replicate further updates for "part2". > I noticed the same behavior with both origins as none and any. i.e > initial sync is ok and then replication of foreign table part2 will > not work which is because of the above restriction that I mentioned. > Just to be sure that I'm not checking a different scenario, could you > share the test for this case. That's right, but i think we must tell user about inappropriate usage. check_publication_add_relation() checks only publication creation for foreign tables directly, but not partitioned tables structure. My test case just shows that we can try to replicate partitioned table with foreign partitions, but I think we should disallow such cases. I would also like to show an interesting subscription creation scenario that I found: 1. subscriber: calls check_publications_origin() 2. publisher: executes the create/attach foreign partition command 3. the subscriber is sure he checked the origin and performing COPY t TO STDOUT i.e. between the check and the start of copying the publication has changed the problem is that check_publications_origin() and COPY t TO STDOUT are performed in different transactions > > [1] - https://www.postgresql.org/docs/devel/logical-replication-restrictions.html > > Regards, > Vignesh