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 1jxE0d-0005YS-Jx for pgsql-general@arkaria.postgresql.org; Sun, 19 Jul 2020 18:25:59 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1jxE0c-0005KR-Eb for pgsql-general@arkaria.postgresql.org; Sun, 19 Jul 2020 18:25:58 +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 1jxE0c-0005KK-6p for pgsql-general@lists.postgresql.org; Sun, 19 Jul 2020 18:25:58 +0000 Received: from mail.am-soft.de ([83.218.36.120]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jxE0V-0001QS-6q for pgsql-general@lists.postgresql.org; Sun, 19 Jul 2020 18:25:57 +0000 Received: from mail.am-soft.de (localhost [127.0.0.1]) by mail.am-soft.de (Postfix) with ESMTP id AD9E82BDE519 for ; Sun, 19 Jul 2020 20:25:49 +0200 (CEST) Received: from tschoening-nb.fritz.box (unknown [77.78.163.99]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.am-soft.de (Postfix) with ESMTPSA id 90D022BDE517 for ; Sun, 19 Jul 2020 20:25:48 +0200 (CEST) Date: Sun, 19 Jul 2020 20:25:47 +0200 From: =?utf-8?Q?Thorsten_Sch=C3=B6ning?= Organization: AM-SoFT GmbH IT-Systeme Message-ID: <1566481610.20200719202547@am-soft.de> To: pgsql-general@lists.postgresql.org Subject: How to restore a dump containing CASTs into a database with a new user? MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-AV-Checked: ClamAV using ClamSMTP List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Hi all, one of my apps and databases uses custom CASTs and is used with the user "postgres" for historical reasons. I would like to change that to use a non-superuser for that app+database only. So I dumped the DB using the C-format and tried to restore into a newly creeated DB: > createuser --encrypted --pwprompt ams_sm_mtg > createdb --encoding=3DUTF-8 --locale=3Dde_DE.UTF-8 --owner=3Dams_sm_mtg -= -template=3Dtemplate0 ams_sm_mtg > pg_restore --dbname=3Dams_sm_mtg --no-owner --role=3Dams_sm_mtg < pg_dump= /dump.c Expectation was that whatever gets created in that DB is owned by the new user. But I'm running into the following error: > pg_restore: [archiver (db)] Error while PROCESSING TOC: > pg_restore: [archiver (db)] Error from TOC entry 2721; 2605 342334 CAST C= AST (character varying AS inet) > pg_restore: [archiver (db)] could not execute query: ERROR: must be owne= r of type character varying or type inet > Command was: CREATE CAST (character varying AS inet) WITH FUNCTION pu= blic.fn_cast_inet_from_varchar(character varying, integer, boolean) AS ASSI= GNMENT; Most things I've found are related to that topic is about PLPGSQL, which is not the problem I have (yet?). Somewhere the use of "-n" has been suggested and restoring succeeds with that, but my CASTs are missing afterwards. So that is not a solution. > pg_restore --dbname=3Dams_sm_mtg --no-owner --role=3Dams_sm_mtg -n public= < pg_dump/dump.c I'm having trouble to understand the root cause and how things should work: Is there some wrong owner in the dump related to anything of the CAST? Or can the CAST really only be created when the new DB-owner owns those types? Is that necessary per database then or globally for the public schema or one of the template databases or ...? What is the proper way to restore a dump containing arbitrary CASTs? I would have expected that pg_restore is handling everything, like it does for all other objects. Thanks! Mit freundlichen Gr=C3=BC=C3=9Fen, Thorsten Sch=C3=B6ning --=20 Thorsten Sch=C3=B6ning E-Mail: Thorsten.Schoening@AM-SoFT.de AM-SoFT IT-Systeme http://www.AM-SoFT.de/ Telefon...........05151- 9468- 55 Fax...............05151- 9468- 88 Mobil..............0178-8 9468- 04 AM-SoFT GmbH IT-Systeme, Brandenburger Str. 7c, 31789 Hameln AG Hannover HRB 207 694 - Gesch=C3=A4ftsf=C3=BChrer: Andreas Muchow