From: Tom Lane <tgl@sss.pgh.pa.us>
To: David G. Johnston <david.g.johnston@gmail.com>
Cc: Avi Weinberg <AviW@gilat.com>
Cc: pgsql-general@lists.postgresql.org <pgsql-general@lists.postgresql.org>
Subject: Re: Logical Replication - Should Destination Table Columns Be Defined With Default Value
Date: Tue, 09 Nov 2021 11:06:22 -0500
Message-ID: <1138318.1636473982@sss.pgh.pa.us> (raw)
In-Reply-To: <CAKFQuwaTLveZQjeo+yPMkWBM=J_2rW5Z120ZdMGHiCVW=bUW0g@mail.gmail.com>
References: <DB9PR07MB718063C946C14D4A6EEDA24DCB929@DB9PR07MB7180.eurprd07.prod.outlook.com>
<CAKFQuwaTLveZQjeo+yPMkWBM=J_2rW5Z120ZdMGHiCVW=bUW0g@mail.gmail.com>
"David G. Johnston" <david.g.johnston@gmail.com> writes:
> On Tue, Nov 9, 2021 at 7:50 AM Avi Weinberg <AviW@gilat.com> 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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-general@postgresql.org
Cc: tgl@sss.pgh.pa.us, david.g.johnston@gmail.com, AviW@gilat.com
Subject: Re: Logical Replication - Should Destination Table Columns Be Defined With Default Value
In-Reply-To: <1138318.1636473982@sss.pgh.pa.us>
References: <DB9PR07MB718063C946C14D4A6EEDA24DCB929@DB9PR07MB7180.eurprd07.prod.outlook.com> <CAKFQuwaTLveZQjeo+yPMkWBM=J_2rW5Z120ZdMGHiCVW=bUW0g@mail.gmail.com> <1138318.1636473982@sss.pgh.pa.us>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox