From: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
---|---|
To: | "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com> |
Cc: | Avi Weinberg <AviW(at)gilat(dot)com>, "pgsql-general(at)lists(dot)postgresql(dot)org" <pgsql-general(at)lists(dot)postgresql(dot)org> |
Subject: | Re: Logical Replication - Should Destination Table Columns Be Defined With Default Value |
Date: | 2021-11-09 16:06:22 |
Message-ID: | 1138318.1636473982@sss.pgh.pa.us |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
"David G. Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com> writes:
> On Tue, Nov 9, 2021 at 7:50 AM Avi Weinberg <AviW(at)gilat(dot)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
From | Date | Subject | |
---|---|---|---|
Next Message | Mark Dilger | 2021-11-09 16:07:47 | Re: Logical Replication - Should Destination Table Columns Be Defined With Default Value |
Previous Message | Avi Weinberg | 2021-11-09 16:02:02 | RE: Logical Replication - Should Destination Table Columns Be Defined With Default Value |