From: Adrian Klaver <adrian.klaver@aklaver.com>
To: Mike Lissner <mlissner@michaeljaylissner.com>
Cc: pgsql-general@lists.postgresql.org
Subject: Re: Errors with schema migration and logical replication — expected?
Date: Wed, 12 Dec 2018 17:06:30 -0800
Message-ID: <0dc10006-a214-c8d0-d59f-e6fceb6a1c27@aklaver.com> (raw)
In-Reply-To: <CAMp9=EzVFLVSf4ff80M7VYpYz0u-nyGPe9eDVjPEX5fAxdTwLw@mail.gmail.com>
References: <CAMp9=Eydz258bTK-7=upANs+Pff4wYymQuG=uNjeupCCrbpKFQ@mail.gmail.com>
<42bcb35c-9173-bb9e-bda6-ea5c5950119b@aklaver.com>
<CAMp9=Eypj1cNtnoW8ahFV25mwx8LjTn1x2quPUE-H6tE+D_9pA@mail.gmail.com>
<953748cf-7271-7230-9158-178c8e4f475e@aklaver.com>
<CAMp9=EyitOD8ODYxWZGpJ6dihAKAoMYa_Lza899qBCub_yQY5Q@mail.gmail.com>
<fe304faa-8470-b3dc-ed3a-e38af587c5d7@aklaver.com>
<CAMp9=Ey2YsSZptvPJ=WYfhjc0uUcJdX6oO2fYk+SCe6C4XDkHQ@mail.gmail.com>
<CAMp9=EzTG4Zv-PQCntsd6GBuCqr5SyMyX=qR84KvMesWQh4ruw@mail.gmail.com>
<76570a30-61f0-470a-ff4b-582eb3e33df9@aklaver.com>
<CAMp9=EzR8SXPWRSYSkh2e3FUdaKJB_BzevtzByZG9Qx_36Jm9w@mail.gmail.com>
<2f98e0cb-0a41-fecb-0ef0-16f288d52e50@aklaver.com>
<CAMp9=EzVFLVSf4ff80M7VYpYz0u-nyGPe9eDVjPEX5fAxdTwLw@mail.gmail.com>
On 12/12/18 3:19 PM, Mike Lissner wrote:
> This sounds *very* plausible. So I think there are a few takeaways:
>
> 1. Should the docs mention that additive changes with NOT NULL
> constraints are bad?
It's not the NOT NULL it's the lack of a DEFAULT. In general a column
with a NOT NULL and no DEFAULT is going to to bite you sooner or later:)
At this point I have gathered enough of those bite marks to just make it
my policy to always provide a DEFAULT for a NOT NULL column.
>
> 2. Is there a way this could work without completely breaking
> replication? For example, should Postgresql realize replication can't
> work in this instance and then stop it until schemas are back in sync,
> like it does with other incompatible schema changes? That'd be better
> than failing in this way and is what I'd expect to happen.
Not sure as there is no requirement that a column has a specified
DEFAULT. This is unlike PK and FK constraint violations where the
relationship is spelled out. Trying to parse all the possible ways a
user could get into trouble would require something on the order of an
AI and I don't see that happening anytime soon.
>
> 3. Are there other edge cases like this that aren't well documented that
> we can expect to creep up on us? If so, should we try to spell out
> exactly *which* additive changes *are* OK?
Not that I know of. By their nature edge cases are rare and often are
dealt with in the moment and not pushed out to everybody. The only
solution I know of is pretesting your schema change/replication setup on
a dev installation.
>
> This feels like a major "gotcha" to me, and I'm trying to avoid those. I
> feel like the docs are pretty lacking here and that others will find
> themselves in similarly bad positions.
Logical replication in core(not the pglogical extension) appeared for
the first time in version 10. On the crawl/walk/run spectrum it is
moving from crawl to walk. The docs will take some time to be more
complete. Just for the record my previous post was sketching out a
possible scenario not an ironclad answer. If you think the answer is
plausible and a 'gotcha' I would file a bug:
https://www.postgresql.org/account/login/?next=/account/submitbug/>
> Better schema migration docs would surely help, too.
>
> Mike
>
>
--
Adrian Klaver
adrian.klaver@aklaver.com
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: adrian.klaver@aklaver.com, mlissner@michaeljaylissner.com
Subject: Re: Errors with schema migration and logical replication — expected?
In-Reply-To: <0dc10006-a214-c8d0-d59f-e6fceb6a1c27@aklaver.com>
References: <CAMp9=Eydz258bTK-7=upANs+Pff4wYymQuG=uNjeupCCrbpKFQ@mail.gmail.com> <42bcb35c-9173-bb9e-bda6-ea5c5950119b@aklaver.com> <CAMp9=Eypj1cNtnoW8ahFV25mwx8LjTn1x2quPUE-H6tE+D_9pA@mail.gmail.com> <953748cf-7271-7230-9158-178c8e4f475e@aklaver.com> <CAMp9=EyitOD8ODYxWZGpJ6dihAKAoMYa_Lza899qBCub_yQY5Q@mail.gmail.com> <fe304faa-8470-b3dc-ed3a-e38af587c5d7@aklaver.com> <CAMp9=Ey2YsSZptvPJ=WYfhjc0uUcJdX6oO2fYk+SCe6C4XDkHQ@mail.gmail.com> <CAMp9=EzTG4Zv-PQCntsd6GBuCqr5SyMyX=qR84KvMesWQh4ruw@mail.gmail.com> <76570a30-61f0-470a-ff4b-582eb3e33df9@aklaver.com> <CAMp9=EzR8SXPWRSYSkh2e3FUdaKJB_BzevtzByZG9Qx_36Jm9w@mail.gmail.com> <2f98e0cb-0a41-fecb-0ef0-16f288d52e50@aklaver.com> <CAMp9=EzVFLVSf4ff80M7VYpYz0u-nyGPe9eDVjPEX5fAxdTwLw@mail.gmail.com> <0dc10006-a214-c8d0-d59f-e6fceb6a1c27@aklaver.com>
* 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