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 1jHkyh-0000Hl-E5 for pgsql-general@arkaria.postgresql.org; Fri, 27 Mar 2020 09:08:35 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1jHkyf-0002jP-LZ for pgsql-general@arkaria.postgresql.org; Fri, 27 Mar 2020 09:08:33 +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 1jHkyf-0002jI-5I for pgsql-general@lists.postgresql.org; Fri, 27 Mar 2020 09:08:33 +0000 Received: from mail-wm1-x334.google.com ([2a00:1450:4864:20::334]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1jHkyX-0003u6-Pn for pgsql-general@postgresql.org; Fri, 27 Mar 2020 09:08:31 +0000 Received: by mail-wm1-x334.google.com with SMTP id b12so10619064wmj.3 for ; Fri, 27 Mar 2020 02:08:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cybertec-at.20150623.gappssmtp.com; s=20150623; h=message-id:subject:from:to:date:in-reply-to:references:user-agent :mime-version:content-transfer-encoding; bh=GQeP1OeLJlHW5S+JHuoEKRV0UX3kgqpjJ3d6gdU4iWQ=; b=HhFoaRpoVFm/MQq1K93S09VlTmF3X1RpMaGOu0VOHPNwf22sZavQY5n/CyjIEQfg9B gBefblcEARzmRtRNb34/SYP4qP0ppgKLMgWGZtik1eZccMS7DWS9mLntNhYkhCV/NMOo xVcPRscHxQrKBc8xkV0zd/NHA4kFBjrP3muiyYieu0h/bvVnqkLviYqAcr/J/3QxrnBz xSk+M7zgbURXuuba7ZtjbW93O92366QnZEv9s07c5xwKr4+LN4DfU7yrpfGV4itUdtov ZggUu8+sQfmYKNti4ulIoxVcHiUkB2RA6tZbA4gf0rpa445RUG/KNnkjD9S+oQ78aMEr m5/Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:subject:from:to:date:in-reply-to :references:user-agent:mime-version:content-transfer-encoding; bh=GQeP1OeLJlHW5S+JHuoEKRV0UX3kgqpjJ3d6gdU4iWQ=; b=blQ2r/Y1U8GszVnnZRfyNGBWpBiUN449p59Tijh6c0IzJYEz+nTsL3cFj6kXDp/gtp x23dUEFn/VYQ1mOIGtSuj7lb87X+Bszaf+CUcJbdn7+AVXVIJXRk0Rz4iDcpy/OtSs5C SqGU4CvMsE8VhQL7/sK39w159OZD+nzvohTz7kJWSGcUC2qlJLAia9uj/JhrImmV7RS4 39ZV9Hs4fwiBeGYEpkt9avvJbyniK2hm5x4OZ1iVUDZT7H4CZIAq9xokFTVcbFfSWNK6 imxdM6D/+Oec0rNJ8+AsMx3DG+HA3AJ0xWShbcdBWJl5ebLiOcfP9P5ezwkGMfVUXgrE oLZQ== X-Gm-Message-State: ANhLgQ1uI6vRXgnrFIAwFiUcHMUMeVkObR2kqfkk2q3D0ssgCfHaygY/ k5taeW8sTo0lFJLZIgHeA5EDvg== X-Google-Smtp-Source: ADFU+vsmpTd+6NhkRmVoMVX0HMixMEe9GGMcUiujXYRGCzU/iiLm8/E8GzuYZ/aCLd6oEK4gVo568w== X-Received: by 2002:a1c:3105:: with SMTP id x5mr4495073wmx.51.1585300102665; Fri, 27 Mar 2020 02:08:22 -0700 (PDT) Received: from dynamic-eost6mr5dos6h0h8d-pd01.res.v6.highway.a1.net (dynamic-eost6mr5dos6h0h8d-pd01.res.v6.highway.a1.net. [2001:871:60:b360:f87:967e:1d40:a03d]) by smtp.gmail.com with ESMTPSA id j11sm7459146wrt.14.2020.03.27.02.08.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 27 Mar 2020 02:08:22 -0700 (PDT) Message-ID: <9e4ee34b262e825dcba8925eb0ec3038e1e48893.camel@cybertec.at> Subject: Re: How can I recreate a view in a new schema such that the view def references tables in the new schema ? From: Laurenz Albe To: David Gauthier , Postgres General Date: Fri, 27 Mar 2020 10:08:21 +0100 In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.32.5 (3.32.5-1.fc30) MIME-Version: 1.0 Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Thu, 2020-03-26 at 13:16 -0400, David Gauthier wrote: > psql (9.6.7, server 11.3) on linux > > I have 2 DBs, differnet servers/instances. I want to take all the metadata and data for a set of tables/views > in the public schema of one DB and move it all over to be inside a schema of a second DB/instance. > > I'm using pg_dump to create the script and I believe I can insert a "set search_path=myschem" in the output > of pg_dump such that when it runs, the "CREATE TABLE", "CREATE VIEW", "GRANT...", etc.... commands, > will all go into the new schema (which I have prepared). Problem is the view defs. > The view defs do not prefix the referenced tables with "myschem.", so the CREATE VIEW xyx commands fail. > > Is there a way to do this ? The best way would be to use pg_dump to move the schema definitions over while preserving the "public" schema, and then use ALTER ... SET SCHEMA newschema; on all objects. Yours, Laurenz Albe -- Cybertec | https://www.cybertec-postgresql.com