Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oqcfU-0000SR-4F for pgsql-general@arkaria.postgresql.org; Thu, 03 Nov 2022 16:02:12 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1oqcfS-0004UJ-0N for pgsql-general@arkaria.postgresql.org; Thu, 03 Nov 2022 16:02:10 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oqcfQ-0004U6-Tk for pgsql-general@lists.postgresql.org; Thu, 03 Nov 2022 16:02:09 +0000 Received: from wout3-smtp.messagingengine.com ([64.147.123.19]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oqcfN-00060H-8N for pgsql-general@postgresql.org; Thu, 03 Nov 2022 16:02:08 +0000 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.west.internal (Postfix) with ESMTP id 46052320091B; Thu, 3 Nov 2022 12:02:00 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute4.internal (MEProxy); Thu, 03 Nov 2022 12:02:00 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aklaver.com; h= cc:content-transfer-encoding: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=fm2; t=1667491319; x= 1667577719; bh=igwyChyNugTR4ni1Ip4JFgSVGCtN2j2awkZf0gGLBQw=; b=l d1BKeMt6DSb1B4D9errQ1woLLCT/QwwL1FMoCibezTzzwAo51QFHETK3bzkqUaug 97FPzXz2YHIKtoXYblyUm/unvQ5mFJHPYcAbYj7bmSASk420IS4mdDDBVg6uJB04 5NFKAqyE4M+xI9dtUapCoSb/7/YZJMhSiNfg4nwdpBfeBLymd9WEtll+fmWq8vhS O4x6hKcV9o0+eAJMQWJiRrKlc582YVwcZ+tJSvh7/SEXR7iiCDuk5o7uTUWDS6+d 5UFcllzDv/RX3utcVl6e1bJme3FR7UELW7I6wZ9BPLDk9FqiutqCWFjnBtKH7TIr 2xTnnYAU0X+zsI5nlJEQw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding: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=fm3; t=1667491319; x=1667577719; bh=i gwyChyNugTR4ni1Ip4JFgSVGCtN2j2awkZf0gGLBQw=; b=XGbT/k5i00Z9JcCse 1K9B1K/HHeFlwMWDrTnJPysSgCmRz4Ns64/zTLDUJgq0/0PbwAlCuN8txfht+rXz zUEmBeFzChQdlE6k+j0gq6o7WrIFe324DXMOsWc+h3OL7/CU3DPnetXE4NP4vAxm rmhHCsh8fII+/ekOn4SRvC4JM8r5UqxRMiQZYFvuGbkhlLLYkRmJS+sbyZs/TIwS OB8F8QuuzXRgkE8SqbM8dwCS2Xpdkw8s1RoMiGHgFQWPrdBZPawDhHg6JT16IRT4 kIHHmiU5xOC54GHpEBlSzA9vFCfQrvw6VFfyWC8TfOZYmlkB54DBHCaP8kl0AoZ0 wWMsA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvgedrudelgdejjecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpefkffggfgfuvfhfhfgjtgfgsehtkeertddtfeejnecuhfhrohhmpeetughrihgr nhcumfhlrghvvghruceorggurhhirghnrdhklhgrvhgvrhesrghklhgrvhgvrhdrtghomh eqnecuggftrfgrthhtvghrnhepleekgeejhfekteehfeduveetheeivdduheekudelteef vdffueehtddvgedtfeefnecuffhomhgrihhnpehpohhsthhgrhgvshhqlhdrohhrghenuc evlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpegrughrihgr nhdrkhhlrghvvghrsegrkhhlrghvvghrrdgtohhm X-ME-Proxy: Feedback-ID: i76984098:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 3 Nov 2022 12:01:59 -0400 (EDT) Message-ID: <2f18c2c1-a002-8a0a-bc98-27feb8553050@aklaver.com> Date: Thu, 3 Nov 2022 09:01:58 -0700 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.4.1 Subject: Re: pg_restore error on function Content-Language: en-US To: Post Gresql , pgsql-general References: <32b7cafd-e649-5478-017d-766036a2afbd@taljaren.se> <70b322b5-74dc-73db-f0b5-c8eaadd2570a@aklaver.com> <173c02e6-c914-b109-9a59-8f516261ebab@taljaren.se> From: Adrian Klaver In-Reply-To: <173c02e6-c914-b109-9a59-8f516261ebab@taljaren.se> 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 11/3/22 08:38, Post Gresql wrote: > > On 2022-11-03 15:43, Adrian Klaver wrote: >> On 11/3/22 07:28, Post Gresql wrote: >>> Hello >>> >>> I first successfully ran >>> >>> pg_dump -U postgres -b -E UTF8 -f my_dump --format=custom -n >>> my_schema --no-owner -v my_db >>> >>> but then >>> >>> pg_restore --single-transaction -v -U postgres -O -e -d my_other_db >>> my_dump >>> >>> failed with >>> >>> pg_restore: connecting to database for restore >>> pg_restore: creating FUNCTION "my_schema.update_b()" >>> pg_restore: [archiver (db)] Error while PROCESSING TOC: >>> pg_restore: [archiver (db)] Error from TOC entry 7142; 1255 8618854 >>> FUNCTION update_b() previous_owner >>> pg_restore: [archiver (db)] could not execute query: ERROR: schema >>> my_schema" does not exist >>>      Command was: CREATE FUNCTION "my_schema".update_b() RETURNS void >>>      LANGUAGE plpgsql >>>      AS $$ >>>              BEGIN >>>              PERFORM pg_advisory_xact_lock(1); >>> >>>              INSERT INTO ...; >>>              END; >>>              $$; >>> >>> >>> This is PG version 10.19 >>> >>> Is there a solution for this (apart from upgrading to a newer PG >>> version)? >> >> Was there another error before this? >> >> Did the -v  show the schema my_schema being created? > > > No there were no other output apart from what I showed above. The -v to pg_restore should output the progress: https://www.postgresql.org/docs/current/app-pgrestore.html -v --verbose Specifies verbose mode. This will cause pg_restore to output detailed object comments and start/stop times to the output file, and progress messages to standard error. Repeating the option causes additional debug-level messages to appear on standard error. Something like: pg_dump -d test -U postgres -Fc -n test -f test_sch.out pg_restore -d t -U postgres -v test_sch.out pg_restore: connecting to database for restore pg_restore: creating SCHEMA "test" pg_restore: creating TABLE "test.c2" pg_restore: creating TABLE "test.supplies" pg_restore: creating SEQUENCE "test.supplies_id_seq" pg_restore: creating SEQUENCE OWNED BY "test.supplies_id_seq" pg_restore: creating TABLE "test.up_test" pg_restore: creating DEFAULT "test.supplies id" pg_restore: processing data for table "test.c2" pg_restore: processing data for table "test.supplies" pg_restore: processing data for table "test.up_test" pg_restore: executing SEQUENCE SET supplies_id_seq pg_restore: creating CONSTRAINT "test.c2 pk1" pg_restore: creating CONSTRAINT "test.supplies supplies_pkey" > > No, no mention of creating the schema. As you see the schema was created first. > > > Btw. it worked fine when I used plain text output and moved the part of > creating the function to near the end of the dump file. > > Could it be that the > > create function  . Well the schema should have already been created. Assuming this: pg_restore: connecting to database for restore pg_restore: creating FUNCTION "my_schema.update_b()" was not the result of an edit then something is not working correctly. What is my_schema.update_b() doing? > > in the dump file does not implicitly create the schema as a > > create table . > > would? > > >> >>> >>> The only workaround I can think of is to dump in plain text and then >>> edit the dump file. >>> >>> >> -- Adrian Klaver adrian.klaver@aklaver.com