Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gX6AR-0003xK-CK for pgsql-general@arkaria.postgresql.org; Wed, 12 Dec 2018 15:11:19 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gX6AQ-0007UH-0g for pgsql-general@arkaria.postgresql.org; Wed, 12 Dec 2018 15:11:18 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gX6AO-0007Ra-Sd for pgsql-general@lists.postgresql.org; Wed, 12 Dec 2018 15:11:17 +0000 Received: from out1-smtp.messagingengine.com ([66.111.4.25]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gX6AK-0002Lq-9S for pgsql-general@lists.postgresql.org; Wed, 12 Dec 2018 15:11:16 +0000 Received: from compute6.internal (compute6.nyi.internal [10.202.2.46]) by mailout.nyi.internal (Postfix) with ESMTP id 3CC83231BD; Wed, 12 Dec 2018 10:11:10 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute6.internal (MEProxy); Wed, 12 Dec 2018 10:11:10 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aklaver.com; h= subject:to:cc:references:from:message-id:date:mime-version :in-reply-to:content-type:content-transfer-encoding; s=fm1; bh=z Bfc/YaPBAgBoFB1vrbCu5PoyyNjbhuvHFLu9CsBDus=; b=dfm/1oVlRLTjqWku2 taf3ee1HVdomxWcRoCW1fQpT/Y7M9Ei/dHGct5HfmDhHJjpG8zJqL2pzTEpgql0i AEu5dTPJom7PEss+Zlt/v4q8ngCSKmJ/r4EvuZBYwLTtpGuYE0DEdxnF3fOWWM1j H2mEuux5JoZo3/Gl6o3/le1ejYXte5U/r4BDhgbtrLhi4epCa2vbzKESvcn7L20S pqzdd2H0twBebGfEkpl3v1ziaKz8aumMlk9SSWfWJrfA9bmitr3X86e4X+389byB u8dlHQMJS6kgHZdc8kv5dVFMTKFJd3AJxklAChZuoDPWARnemuvLJZ+/qhuRWOBl gSOSg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm1; bh=zBfc/YaPBAgBoFB1vrbCu5PoyyNjbhuvHFLu9CsBD us=; b=oYHuiu4po5VXoRshs6D3k1sPHx1iXx5MHtpEvvIk3hF/i7JYCOQvaSx68 n8vqvdFtbUFipN7HjbC74BDT8SwIQBt4SB5qjjiY2TOz+6cFCgSTwCBtjr1qLHL7 WPVTqnZIKiHQnYz1NF7JgLsNYQ34dG6M1m28+m+Vp8lINnrqaL2M6n/w3lY2cwip w/qDgwu+dGmmmx0KXuKKTRMCjqfB+8Wfx/sTFoYtJUKvNk58JaOCXpd1+0k+Dsrj o6GkcPyKKQh9BAn2H3qU1BZBNdRG/MOM/F7OBfOiVEUhfJ/y6JCcHW/bLWeGRoWZ 3BLbNWxMafFN5ObBUBpu/Gf/4rQ2g== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedtkedrudegledgjeefucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfquhhtnecuuegrihhlohhuthemucef tddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjughrpefuvfhfhffkff gfgggjtgfgsehtkeertddtfeejnecuhfhrohhmpeetughrihgrnhcumfhlrghvvghruceo rggurhhirghnrdhklhgrvhgvrhesrghklhgrvhgvrhdrtghomheqnecuffhomhgrihhnpe hpohhsthhgrhgvshhqlhdrohhrghenucfkphepjedurddvuddvrddufeegrdefnecurfgr rhgrmhepmhgrihhlfhhrohhmpegrughrihgrnhdrkhhlrghvvghrsegrkhhlrghvvghrrd gtohhmnecuvehluhhsthgvrhfuihiivgeptd X-ME-Proxy: Received: from [192.168.1.3] (unknown [71.212.134.3]) by mail.messagingengine.com (Postfix) with ESMTPA id 17D0BE446A; Wed, 12 Dec 2018 10:11:08 -0500 (EST) Subject: =?UTF-8?Q?Re=3a_Errors_with_schema_migration_and_logical_replicatio?= =?UTF-8?B?biDigJQgZXhwZWN0ZWQ/?= To: Mike Lissner Cc: pgsql-general@lists.postgresql.org References: <42bcb35c-9173-bb9e-bda6-ea5c5950119b@aklaver.com> <953748cf-7271-7230-9158-178c8e4f475e@aklaver.com> <76570a30-61f0-470a-ff4b-582eb3e33df9@aklaver.com> From: Adrian Klaver Message-ID: <2f98e0cb-0a41-fecb-0ef0-16f288d52e50@aklaver.com> Date: Wed, 12 Dec 2018 07:11:08 -0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.3.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 12/12/18 12:15 AM, Mike Lissner wrote: > > > On Tue, Dec 11, 2018 at 3:10 PM Adrian Klaver > 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