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.92) (envelope-from ) id 1jCBRe-0004gt-At for pgsql-general@arkaria.postgresql.org; Thu, 12 Mar 2020 00:11:26 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1jCBRd-0004l6-82 for pgsql-general@arkaria.postgresql.org; Thu, 12 Mar 2020 00:11:25 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1jCBRb-0004kz-QY for pgsql-general@lists.postgresql.org; Thu, 12 Mar 2020 00:11:24 +0000 Received: from [66.111.4.26] (helo=out2-smtp.messagingengine.com) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jCBRY-0007xB-Rq for pgsql-general@postgresql.org; Thu, 12 Mar 2020 00:11:22 +0000 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id D842C22028; Wed, 11 Mar 2020 20:11:09 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute4.internal (MEProxy); Wed, 11 Mar 2020 20:11:09 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aklaver.com; h= subject:to:references:from:message-id:date:mime-version :in-reply-to:content-type:content-transfer-encoding; s=fm2; bh=N OWUfg6aCVfFZo7BEvHU0dxJJKGQuUs4g8VonAATs5Y=; b=PjE5Pzl3fm3dk+Sb8 Tbt6Y+hRQZSTAYl/WUWf2+Ee1Y80s5b8BsG8c61AzS2woR2aX8EGG3i+1tUwdvDW KKGYdsCGd/hO0cD9bV+FXIy66SVxX38Ok1AGzGbSX3BoTw+exsr5rmZ/F5Majslp hZtLY3/e0DZDlCFmK2kYXqamauUvr51mm/+2UXOxb5hzlRwbeR+O8cq3xJjY9udc aoQFj9268GLko0CIlHvkfNnIZsVTVAbRUDTLHS2fgj+7iaXxYeTpnwsc2SB44PTc TIs8Q7TC8xa2ZKxlCGPBRMfH6kIf4//9AWfPYTr+vK19FO9fMWE7vrcVSFhiyL07 uNxRQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=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=fm2; bh=NOWUfg6aCVfFZo7BEvHU0dxJJKGQuUs4g8VonAATs 5Y=; b=KBeowoEdhgXFNHu8sM314BNS600I3ZIS+0cvxYeyLUcSR88QjiPCuZaPW ZOO8jE95p3OZnyXTPM3AIvAlu8v3BVxDhWU6IiDP0aAkdtahDU2e9da0pamkpRtz nlXTRoZlXVnSlzsXDoFLpE7CrCfhajhi+Gpgt1e+fpbNlo+diMod4qu5RcE/0fhX 5MfZLKjpTorqGaaQ/Eu0WoVyn9i1w/3XznM2sdeDnJb1rdisn6PBi4oygQSodEvb J+veyQLBPoBdpZ58K1j1OOCYp07Aw/Bc/JW4t8v/I1123XxHfvsbOHxP4/5oFrbB t37AxlIBF6dJJ29jphHW8JPNzS9mQ== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedugedruddvgedgfeduucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepuffvfhfhkffffgggjggtgfesthejredttdefjeenucfhrhhomheptegurhhi rghnucfmlhgrvhgvrhcuoegrughrihgrnhdrkhhlrghvvghrsegrkhhlrghvvghrrdgtoh hmqeenucfkphepjedurddvuddvrdduvdelrdduleefnecuvehluhhsthgvrhfuihiivgep tdenucfrrghrrghmpehmrghilhhfrhhomheprggurhhirghnrdhklhgrvhgvrhesrghklh grvhgvrhdrtghomh X-ME-Proxy: Received: from [192.168.1.10] (unknown [71.212.129.193]) by mail.messagingengine.com (Postfix) with ESMTPA id 1DD5530611FB; Wed, 11 Mar 2020 20:11:09 -0400 (EDT) Subject: Re: pg_restore restores out of order To: Kevin Brannen , "pgsql-general@postgresql.org" References: <0e314bd5-5611-e70f-eb4a-c3c2a5fe232f@aklaver.com> From: Adrian Klaver Message-ID: <619e3acf-7b6a-58ba-8bf2-905000e37cdf@aklaver.com> Date: Wed, 11 Mar 2020 17:11:08 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.5.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-Host-Lookup-Failed: Reverse DNS lookup failed for 66.111.4.26 (deferred) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 3/11/20 4:11 PM, Kevin Brannen wrote: >> Adrian Klaver wrote: >> On 3/11/20 2:46 PM, Kevin Brannen wrote: >>> I'm working thru our system to upgrade from 9.6.5 to 12.2. One of the last things I'm verifying is backup/restore and it's failing for no reason I can figure out. So I'm looking for pointers on this. >>> >>> If it matters, the code is from the version 12.2 from the Pg site, RPMs for Centos 6 (.10). >>> >>> The backup is made like: >>> >>> # $PGPATH/pg_dump --format=d --jobs=2 --file=$exp --dbname=nms >>> --schema=public >> >> Which version of pg_dump 9.6.5 or 12.2? > > Both pg_dump and pg_restore are with 12.2, on an already converted 12.2 DB. > So I'm 12.2 all the way on my test system by this point. :) > >>> ... >>> So we move the current schema to the side just in case something goes wrong and we need to move it back, create an empty schema for it, then restore into that schema. Then it goes bad... >>> >>> pg_restore: while PROCESSING TOC: >>> pg_restore: from TOC entry 6356; 0 23653 TABLE DATA subscribers >>> nmsroot >>> pg_restore: error: COPY failed for table "subscribers": ERROR: relation "su_profiles" does not exist >>> LINE 1: SELECT srvc_data FROM su_profiles WHERE su_profile... >>> ^ >>> QUERY: SELECT srvc_data FROM su_profiles WHERE su_profile_pk = p_profile_fk >>> CONTEXT: PL/pgSQL function public.check_data_ip(integer,integer,character varying) line 7 at SQL statement >>> COPY subscribers, line 1: "61 1002 \N SU_1002 t \N 4 \N 1 250 0 2015-06-22 16:56:27.79333+00 nmsmgr \N \N \N" >> >> What is in public.check_data_ip(integer,integer,character varying)? >> >> Is it a trigger function on subscribers? > > Not quite... > > nms=# \d subscribers > Table "public.subscribers" > ... > Check constraints: > "chk_su_data_ip" CHECK (check_data_ip(profile_fk, unit_id, data_ip)) > > > The first line of the check_data_ip() function is the offender: > > SELECT srvc_data INTO data > FROM su_profiles > WHERE su_profile_pk = p_profile_fk; > > Hmm, why is this a problem now and not before? > > (Probably the usual reason of code "tightening" as we go forward, or so I'd guess.) > > I don't see any option that mentions "CHECK" in the pg_restore doc in regards to > possibly turning it off...more research... > > And oh, this hurts. :( From the docs on CHECK constraints: > > PostgreSQL does not support CHECK constraints that reference table data other > than the new or updated row being checked. While a CHECK constraint that > violates this rule may appear to work in simple tests, it cannot guarantee > that the database will not reach a state in which the constraint condition > is false (due to subsequent changes of the other row(s) involved). This > would cause a database dump and reload to fail. ... > > It goes on to say a trigger is the right way to do this. So yeah, a "tightening > of the code" seems to be hitting me because of bad code from the past. > > Problem identified and I'll solve it tomorrow. Glad it was solved. However, looking a gift horse in the mouth, did this not error when moving from the 9.6.5 instance to the first 12.2 instance? Or Was the constraint added in the first 12.2 instance? > > Thank you so much Adrian for helping me to figure this out! > > Kevin -- Adrian Klaver adrian.klaver@aklaver.com