Logical Replication - Adding Not-Null Column Without Default Value

From: Avi Weinberg <AviW(at)gilat(dot)com>
To: "pgsql-general(at)lists(dot)postgresql(dot)org" <pgsql-general(at)lists(dot)postgresql(dot)org>
Subject: Logical Replication - Adding Not-Null Column Without Default Value
Date: 2023-10-17 14:05:38
Message-ID: DB9PR07MB718081ECF085D13491D1CAA0CBD6A@DB9PR07MB7180.eurprd07.prod.outlook.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi Experts,

I'm using logical replication with Postgres 15.

I added not-null column without default value to one of my published tables. The way I so it on publisher side is to add the column as nullable, then update the value based on some logic, and finally make the column not-null.

On the subscriber side, if add the column as nullable then add dummy value and finally make it not-null (all in a single truncation), will it be safe to say that the correct values of this column will be logically synchronized from publisher to subscriber and will override the dummy values. Would, at the end, the two tables on publisher and subscriber have exactly the same values for this column.

Do you see a scenario that the tables will not be the same? Is there a better way to add a not-null column without default value on subscriber side?

Thanks

IMPORTANT - This email and any attachments is intended for the above named addressee(s), and may contain information which is confidential or privileged. If you are not the intended recipient, please inform the sender immediately and delete this email: you should not copy or use this e-mail for any purpose nor disclose its contents to any person.

Browse pgsql-general by date

  From Date Subject
Next Message Dominique Devienne 2023-10-17 14:16:14 Parsing libpq PQtrace files
Previous Message Ron 2023-10-17 13:39:35 Re: PITR partial timing