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 1mkTdq-000715-94 for pgsql-general@arkaria.postgresql.org; Tue, 09 Nov 2021 16:06:34 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1mkTdo-0006rM-EJ for pgsql-general@arkaria.postgresql.org; Tue, 09 Nov 2021 16:06:32 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mkTdo-0006rC-3Q for pgsql-general@lists.postgresql.org; Tue, 09 Nov 2021 16:06:32 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mkTdl-0001ff-Qd for pgsql-general@lists.postgresql.org; Tue, 09 Nov 2021 16:06:31 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 1A9G6M2x1138319; Tue, 9 Nov 2021 11:06:22 -0500 From: Tom Lane To: "David G. Johnston" cc: Avi Weinberg , "pgsql-general@lists.postgresql.org" Subject: Re: Logical Replication - Should Destination Table Columns Be Defined With Default Value In-reply-to: References: Comments: In-reply-to "David G. Johnston" message dated "Tue, 09 Nov 2021 08:54:41 -0700" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <1138317.1636473982.1@sss.pgh.pa.us> Date: Tue, 09 Nov 2021 11:06:22 -0500 Message-ID: <1138318.1636473982@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk "David G. Johnston" writes: > On Tue, Nov 9, 2021 at 7:50 AM Avi Weinberg wrote: >> Was this done on purpose, that default value for new column is not copied >> for existing data? Does this mean that on destination side we must also >> define the table with default value? > If you run a command on the publisher that causes every row to change then > of course every row will be published with those new values to the > subscriber. I think the important point here is that the ALTER ADD COLUMN operation *didn't* cause a physical update of every row on the publisher, thus nothing got sent to the subscriber. This is sort of annoying, because it is making what ought to be a purely internal optimization user-visible. Depending on the details of the column default (is it null, is it a constant) and which PG version you are talking about, there may or may not be a rewrite of the source table, and here we see that that is semantically visible to subscribers. I don't want to give up the aforesaid optimization --- it's a feature that you can do common forms of ALTER ADD COLUMN in O(1) time. But maybe we ought to document the implications for logical replication better. regards, tom lane