Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1qiG4v-005lUg-VN for pgsql-general@arkaria.postgresql.org; Mon, 18 Sep 2023 15:22:25 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1qiG4u-001wjT-El for pgsql-general@arkaria.postgresql.org; Mon, 18 Sep 2023 15:22:24 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1qiG2l-001u5A-7B for pgsql-general@lists.postgresql.org; Mon, 18 Sep 2023 15:20:11 +0000 Received: from out5-smtp.messagingengine.com ([66.111.4.29]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1qiG2h-005H5Z-W9 for pgsql-general@lists.postgresql.org; Mon, 18 Sep 2023 15:20:09 +0000 Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.nyi.internal (Postfix) with ESMTP id 61B4C5C0099; Mon, 18 Sep 2023 11:20:07 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute1.internal (MEProxy); Mon, 18 Sep 2023 11:20:07 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aklaver.com; h= cc:content-transfer-encoding:content-type:content-type:date:date :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:sender:subject:subject:to:to; s=fm1; t= 1695050407; x=1695136807; bh=VPsZKnVgoG5BYXV86OajFIh5sN3dl1++NR7 xwRK4tEo=; b=eeOFOCDyTNQ1aZPuJhkhHmrI/Lgf7+8WHCY8j3K0d+jESiS6cwh BebIwQhkS4hixZ5JY5/G+y+YfMnbmTx6LdjlT8ET4AllWhw61tocEwPOHTFLSbcJ LlnrSXh2MECKD9VzG5ujlmyjEx1QxfrwrPqpfJlfmbZ8XD2QL43fL2beVRgsKMyB lPIDnrwAiMan0vjxCmGXQE2dK97e7cc5gstNXWJIG4PW7J40J6Wxtt+eiDsaiMvn uEYa771soSncd4F2Jy9mCWNw1RoweFZUnS20B4bTuih9DwZVr1TXQA6Ot/ZPiE73 95pxtxQSlglgYse761bffql0if+wXR2GA0Q== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:sender:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm2; t=1695050407; x= 1695136807; bh=VPsZKnVgoG5BYXV86OajFIh5sN3dl1++NR7xwRK4tEo=; b=L gPQE3cD/QE233VwsO8TBWnL65pwl0pO1Ep8iOTXs4YYhozvcRLa1R8JxvhZOn04N +oJK5BGACRFhzvPEszTUTd+kTUe8LGsYNVyicZQnDNMOEdBmtbCwt8u7IgBPZb+p KpMqtMU6HxrxFmDW7XoIIuQb+Y/o9sMtuI9ya3natgz+PHl9lnnWGyBJcG4BxWnq WO44lHynZVr56Qac08vT86FyogOE1wTOotUdqJtr6mklCkpc3MlXySNOUpTPutdF HntDBalsbJA9l+Mymh7Zk0WJqnxiRjhexXbalds95VGDBJFJu2HFtwGke9ct4Efw BfSuzasBxXywP5XjUZ2+g== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedviedrudejkedgkeeiucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepkfffgggfuffhvfhfjggtgfesthekredttdefjeenucfhrhhomheptegurhhi rghnucfmlhgrvhgvrhcuoegrughrihgrnhdrkhhlrghvvghrsegrkhhlrghvvghrrdgtoh hmqeenucggtffrrghtthgvrhhnpefgtdevgfffhfelgeevieejfeevkeetveekgffftdef keelgeelvdehgeefudekgeenucffohhmrghinhepphhoshhtghhrvghsqhhlrdhorhhgne cuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomheprggurhhi rghnrdhklhgrvhgvrhesrghklhgrvhgvrhdrtghomh X-ME-Proxy: Feedback-ID: i76984098:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 18 Sep 2023 11:20:06 -0400 (EDT) Message-ID: Date: Mon, 18 Sep 2023 08:20:06 -0700 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.15.1 Subject: Re: trouble restoring a database backed up with pg_dump/pg_dump_all - relations are created in the wrong order Content-Language: en-US From: Adrian Klaver To: Harry Green , "pgsql-general@lists.postgresql.org" References: <73791286.4632684.1695049729344.ref@mail.yahoo.com> <73791286.4632684.1695049729344@mail.yahoo.com> <015fcbcb-774a-a1e9-0c73-ed93a1f9e30a@aklaver.com> In-Reply-To: <015fcbcb-774a-a1e9-0c73-ed93a1f9e30a@aklaver.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 9/18/23 08:16, Adrian Klaver wrote: > On 9/18/23 08:08, Harry Green wrote: >> Hello, >> >> I am having trouble restoring a database backed up with >> pg_dump/pg_dump_all. The error messages I get are below and appear to >> suggest that certain sql-language or pl/pgsql-language functions which >> include an sql statement referencing a table are trying to be executed >> before the table which they reference has been created. I am surprised >> that pg_dump could get the order wrong, but that is what is happening. >> >> Looking at the first of the error messages, the pl/pgsql function is >> created as /*create  function >> public.check_account_from_bill_items(character...) */on line 95, but >> the instruction to create the accounts table /*'... create table >> public.accounts ... '*/ appears on line 510. > > I'm betting this a function being used in a table CHECK and per: > > https://www.postgresql.org/docs/current/sql-createtable.html > > "Currently, CHECK expressions cannot contain subqueries nor refer to > variables other than columns of the current row (see Section 5.4.1). The > system column tableoid may be referenced, but not any other system column." > > There is no dependency checking for CHECK functions. Forgot to add to above, that if you want to do this sort of thing then use a trigger. In a dump/restore they are added back to the tables after the tables and table data have been restored. > >> >> Consequently, the restore does not work because the relations are >> created in the wrong order. Any ideas how I can solve it? >> >> Please see the error message below: > >> Thanks a lot! >> >> > -- Adrian Klaver adrian.klaver@aklaver.com