pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
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 07:11:08 -0800
Message-ID: <2f98e0cb-0a41-fecb-0ef0-16f288d52e50@aklaver.com> (raw)
In-Reply-To: <CAMp9=EzR8SXPWRSYSkh2e3FUdaKJB_BzevtzByZG9Qx_36Jm9w@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>

On 12/12/18 12:15 AM, Mike Lissner wrote:
> 
> 
> On Tue, Dec 11, 2018 at 3:10 PM Adrian Klaver <adrian.klaver@aklaver.com 
> <mailto:adrian.klaver@aklaver.com>> wrote:
> 
> 
>      >     Well, I was able to fix this by briefly allowing nulls on the
>      >     subscriber, letting it catch up with the publisher, setting all
>      >     nulls to empty strings (a Django convention), and then
>     disallowing
>      >     nulls again. After letting it catch up, there were 118 nulls
>     on the
>      >     subscriber in this column:
> 
>     So recap_sequence_number is not actually a number, it is a code?
> 
> 
> It has sequential values, but they're not necessarily numbers.
> 
> 
>      >
>      >     I appreciate all the responses. I'm scared to say so, but I think
>      >     this is a bug in logical replication. Somehow a null value
>     appeared
>      >     at the subscriber that was never in the publisher.
>      >
>      >     I also still have this question/suggestion from my first email:
>      >
>      >      > Is the process for schema migrations documented somewhere
>     beyond
>      >     the above?
> 
>     Not that I know of. It might help, if possible, to detail the steps in
>     the migration. Also what program you used to do it. Given that is
>     Django
>     I am assuming some combination of migrate, makemigrations and/or
>     sqlmigrate.
> 
> 
> Pretty simple/standard, I think:
>   - Changed the code.
>   - Generated the migration using manage.py makemigration
>   - Generated the SQL using sqlmigrate
>   - Ran the migration using manage.py migrate on the master and using 
> psql on the replica

The only thing I can think of involves this sequence on the subscriber:

ALTER TABLE "search_docketentry" ADD COLUMN "recap_sequence_number" 
varchar(50) DEFAULT '' NOT NULL;
ALTER TABLE "search_docketentry" ALTER COLUMN "recap_sequence_number" 
DROP DEFAULT;

and then this:

https://www.postgresql.org/docs/11/logical-replication-subscription.html

"Columns of a table are also matched by name. A different order of 
columns in the target table is allowed, but the column types have to 
match. The target table can have additional columns not provided by the 
published table. Those will be filled with their default values."

https://www.postgresql.org/docs/10/sql-createtable.html

"If there is no default for a column, then the default is null."

So the subscriber finished the migration first, as alluded to in an 
earlier post. There is no data for recap_sequence_number coming from the 
provider so Postgres place holds the data with NULL until such time as 
the migration on the provider finishes and actual data for 
recap_sequence_number starts flowing.

Going forward, options I see:

1) Making sure there is a DEFAULT other then NULL for a NOT NULL column.

2) Stop the replication and do the migration scripts on both provider 
and subscriber until they both complete and then start replication again.




> Mike


-- 
Adrian Klaver
adrian.klaver@aklaver.com




view thread (14+ messages)  latest in thread

Message-ID: <2f98e0cb-0a41-fecb-0ef0-16f288d52e50@aklaver.com>
Permalink:  ../2f98e0cb-0a41-fecb-0ef0-16f288d52e50@aklaver.com/
Also on:    postgresql.org/message-id/2f98e0cb-0a41-fecb-0ef0-16f288d52e50@aklaver.com

 · 

reply

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: <2f98e0cb-0a41-fecb-0ef0-16f288d52e50@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>

* 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