Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oLxYH-0003dd-I1 for pgsql-hackers@arkaria.postgresql.org; Thu, 11 Aug 2022 02:04:02 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1oLxYG-0002BU-20 for pgsql-hackers@arkaria.postgresql.org; Thu, 11 Aug 2022 02:04:00 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oLxYE-0002BF-Cm for pgsql-hackers@lists.postgresql.org; Thu, 11 Aug 2022 02:03:59 +0000 Received: from wout5-smtp.messagingengine.com ([64.147.123.21]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oLxYB-0007TH-Bz for pgsql-hackers@postgresql.org; Thu, 11 Aug 2022 02:03:57 +0000 Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailout.west.internal (Postfix) with ESMTP id 8C93632000D9; Wed, 10 Aug 2022 22:03:52 -0400 (EDT) Received: from imap49 ([10.202.2.99]) by compute2.internal (MEProxy); Wed, 10 Aug 2022 22:03:52 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=eulerto.com; h= cc:content-type:date:date:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:sender:subject :subject:to:to; s=fm2; t=1660183432; x=1660269832; bh=eQ93SZhPw0 cBU+Ok8SubpqPGN8iRfUg6GvpPi1/rKWo=; b=eq+F1orVkRDWdAePxK/9NiNt2Z kdu5N6EbxIOwqXAfJolutZ637lBQCSpQzuTQnxasiCuG/j5tP5jqlV4ESqLQmEy9 6C3gXa+SO6thrEFnF7mY/K7tmNCk7Q6l90P8/PFxQzM2Hip1ZyIDZU8etN6GSseF d4Tm5Jv0aZJXuDRLUnaZAt2IfjIflcxTi9+u47A2CO1LI21CzIJMtfSNSvX8/e9K 7gXYIozYTlahMtbS4Bgn5Ppdaqr3QUq2r2hdd71HG9KwBoT9LRlQJnoE7jGHvWNu 8HcQaQ7m41jnzNDeyNxTrrOdWihsmptg582QIevuNysunQhFvZ306T6W0plg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:date:date:feedback-id :feedback-id:from:from:in-reply-to:in-reply-to:message-id :mime-version:references:reply-to:sender:subject:subject:to:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm1; t=1660183432; x=1660269832; bh=eQ93SZhPw0cBU+Ok8SubpqPGN8iR fUg6GvpPi1/rKWo=; b=ncZYjjrtYmnwQU3lgFbhLVSRFxDJ4KpnmXH0U91UDhsU 6Rglv1Mq7j5o+xStiirTvvHhOqGjzkVOZCaZbpPLRh/czxNg1j8VTxt+w51u2Zt7 1vqVxL+IhOljq8E7uQ/9umf8omu7TsIv32cZv9E7JXWp3CX6UWg2gZxZDrJ3jb/L KVxLU7Euacy1Rgs1SeLiWNsInm77IizNNf/xEF8rAjNWprh/jW96MvmwbZLK55eE /dtC5UBBUmPvgvnlrGkCM38+9vLKxkv0rxHIQ2L8S7c5Fv9uQ1MIVJAMpSqqIWd+ WQImZGFiMmCQDJ9BDo9rweHRqHV4Fpfni74D6qL75g== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvfedrvdegfedgheehucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepofgfggfkjghffffhvffutgesrgdtreerreertdenucfhrhhomhepfdfguhhl vghrucfvrghvvghirhgrfdcuoegvuhhlvghrsegvuhhlvghrthhordgtohhmqeenucggtf frrghtthgvrhhnpeejtefhuedvgffftdetvedufedtjeeuffekleevkefhveekgeelfefh jeehtdejgeenucffohhmrghinhepvghnthgvrhhprhhishgvuggsrdgtohhmnecuvehluh hsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepvghulhgvrhesvghu lhgvrhhtohdrtghomh X-ME-Proxy: Feedback-ID: i0c21471d:Fastmail Received: by mailuser.nyi.internal (Postfix, from userid 501) id C306515A008B; Wed, 10 Aug 2022 22:03:51 -0400 (EDT) X-Mailer: MessagingEngine.com Webmail Interface User-Agent: Cyrus-JMAP/3.7.0-alpha0-811-gb808317eab-fm-20220801.001-gb808317e Mime-Version: 1.0 Message-Id: <2ebc7ea8-3c46-474e-aea7-5d73ff6165fb@www.fastmail.com> In-Reply-To: References: Date: Wed, 10 Aug 2022 23:03:04 -0300 From: "Euler Taveira" To: "Melih Mutlu" , pgsql-hackers Subject: Re: Allow logical replication to copy tables in binary format Content-Type: multipart/alternative; boundary=4d0fcfacb8974cc1a3e6a3b3505a133e List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --4d0fcfacb8974cc1a3e6a3b3505a133e Content-Type: text/plain On Wed, Aug 10, 2022, at 12:03 PM, Melih Mutlu wrote: > I see that logical replication subscriptions have an option to enable binary [1]. > When it's enabled, subscription requests publisher to send data in binary format. > But this is only the case for apply phase. In tablesync, tables are still copied as text. This option could have been included in the commit 9de77b54531; it wasn't. Maybe it wasn't considered because the initial table synchronization can be a separate step in your logical replication setup idk. I agree that the binary option should be available for the initial table synchronization. > To copy tables, COPY command is used and that command supports copying in binary. So it seemed to me possible to copy in binary for tablesync too. > I'm not sure if there is a reason to always copy tables in text format. But I couldn't see why not to do it in binary if it's enabled. The reason to use text format is that it is error prone. There are restrictions while using the binary format. For example, if your schema has different data types for a certain column, the copy will fail. Even with such restrictions, I think it is worth adding it. > You can find the small patch that only enables binary copy attached. I have a few points about your implementation. * Are we considering to support prior Postgres versions too? These releases support binary mode but it could be an unexpected behavior (initial sync in binary mode) for a publisher using 14 or 15 and a subscriber using 16. IMO you should only allow it for publisher on 16 or later. * Docs should say that the binary option also applies to initial table synchronization and possibly emphasize some of the restrictions. * Tests. Are the current tests enough? 014_binary.pl. -- Euler Taveira EDB https://www.enterprisedb.com/ --4d0fcfacb8974cc1a3e6a3b3505a133e Content-Type: text/html Content-Transfer-Encoding: quoted-printable
On Wed, Aug 10,= 2022, at 12:03 PM, Melih Mutlu wrote:
I see that logical replication subscriptions have an option to en= able binary [1]. 
When it's enabled, subscription req= uests publisher to send data in binary format. 
But t= his is only the case for apply phase. In tablesync, tables are still cop= ied as text.
This option co= uld have been included in the commit 9de77b54531; it wasn't.
Maybe it wasn't considered because the initial table synchronization = can be a
separate step in your logical replication setup i= dk. I agree that the binary
option should be available for= the initial table synchronization.

To copy tables, COPY command is used and that command= supports copying in binary. So it seemed to me possible to copy in bina= ry for tablesync too.
I'm not sure if there is a reas= on to always copy tables in text format. But I couldn't see why not to d= o it in binary if it's enabled.
=
The reason to use text format is that it is error prone. There are = restrictions
while using the binary format. For example, i= f your schema has different data
types for a certain colum= n, the copy will fail. Even with such restrictions, I
thin= k it is worth adding it.

You can find the small patch that only enables binary copy attac= hed.  
I have a f= ew points about your implementation.

* Are = we considering to support prior Postgres versions too? These releases
  support binary mode but it could be an unexpected beh= avior (initial sync in
  binary mode) for a publisher= using 14 or 15 and a subscriber using 16. IMO
  you = should only allow it for publisher on 16 or later.
* Docs = should say that the binary option also applies to initial table
  synchronization and possibly emphasize some of the restrict= ions.
* Tests. Are the current tests enough? 014_binary.pl= .


--
Euler Taveira
=
--4d0fcfacb8974cc1a3e6a3b3505a133e--