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.89) (envelope-from ) id 1gwaTc-000788-4C for pgsql-general@arkaria.postgresql.org; Wed, 20 Feb 2019 22:36:28 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gwaTY-0004e6-SG for pgsql-general@arkaria.postgresql.org; Wed, 20 Feb 2019 22:36:24 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gwaTY-0004dz-HH for pgsql-general@lists.postgresql.org; Wed, 20 Feb 2019 22:36:24 +0000 Received: from mail-pf1-x429.google.com ([2607:f8b0:4864:20::429]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gwaTW-0003ZP-5I for pgsql-general@lists.postgresql.org; Wed, 20 Feb 2019 22:36:24 +0000 Received: by mail-pf1-x429.google.com with SMTP id n74so12656823pfi.9 for ; Wed, 20 Feb 2019 14:36:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-language; bh=dL4W0LZhNdFVHSmZvbedfahbKVI/49ptPMoFKLGlnFo=; b=kozos+VoyG6eqt3K90VJxybYYLs1snFZvjMG3Ddj7NIDtsek87DZEgafbUBE1N5enB IfNQmljh6DGC7pqU5tuNdAgzpWv4UKPFZx5K39de4LYjN5ESX98KqgpTb7wmJXveEkED z4X3zNjeiC5CenMDr3vqB0xoFkY2xxs8aXae2eMwvxnljcX/gAmbXRt1vEXQ7Jf9lGoV 3wGhl9r4vcc1nys8guq81pT+hw+6CX6yiqYdfGRORZRLK0zRNfHCMEqq2RTRaaib0mYF qy8nXo0tZQTBb0Yg2Qd6ncG8l/DOA4SPtV+vGkHAy/FtfoBU/SrDRTt49TkQJYWR3KGa EkbA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language; bh=dL4W0LZhNdFVHSmZvbedfahbKVI/49ptPMoFKLGlnFo=; b=aB7J4x/ZOFf7R5kcyfv0YdKeetzgrihBabY4UVSVWZqbHHt/59boPxTbbIARLv3QCE GLkbbkU8zrVWLBzKnAS5nbVNYBrSsN0fiwp+tZfH0FWYsiocAsqDiLQkpnAZePWOjWOk 2WuXZykQy4f2+5x6OMe/YQGevePUXLBFIS1xa6JT3a75UvdIo/zt0iuywaNQ66NjY93M BIEPSRIy+Z4B4m1hv3fHBzNgbJluXGBZknLr1k/NW9w3MnTbe0xzt+okUzphHwlxt5eq s/NK2aoWfxqv7vE5TFGsWixGJYEjdjti/yO9t2fPIbgR1IHSvECAAVfATGTBfu0FrNd7 DPKA== X-Gm-Message-State: AHQUAubBIKqTVv1rIWgG5SAsj0yGOA16gcL9nW+CRh3vNB1zNyzFP66T MN95GIb6TD7JgciY3YT8ouIZdGpI X-Google-Smtp-Source: AHgI3IaZbtQchzM352x8Wr+wCyxete0RSQNc/PUtRWVFEhHtO+abvenxdR2NRQyv694GpY3VUnpC0Q== X-Received: by 2002:a63:5b43:: with SMTP id l3mr21779280pgm.298.1550702179255; Wed, 20 Feb 2019 14:36:19 -0800 (PST) Received: from [10.104.134.14] ([155.100.47.6]) by smtp.gmail.com with ESMTPSA id h64sm475563pfj.40.2019.02.20.14.36.18 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 20 Feb 2019 14:36:18 -0800 (PST) Subject: Re: Copy entire schema A to a different schema B To: pgsql-general@lists.postgresql.org References: <9aa9cb06-8bca-910c-5251-d974849dda7c@gmail.com> <65a629f9-6745-6cec-30d0-87eaf1ffa7bf@aklaver.com> From: Rob Sargent Message-ID: Date: Wed, 20 Feb 2019 15:36:16 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.4.0 MIME-Version: 1.0 In-Reply-To: Content-Type: multipart/alternative; boundary="------------2D3579131E70EBB661D08F1F" Content-Language: en-US List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk This is a multi-part message in MIME format. --------------2D3579131E70EBB661D08F1F Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit On 2/20/19 3:22 PM, Tiffany Thang wrote: > Hi Adrian, > I managed to backup my table in parallel using -Fd but I'm back to my > original issue where I could not restore the table to a different schema. > > For example, > I would like to backup testuser1.mytable and restore it to > testuser2.mytable. > > pg_dump -U testuser1 -Fd -f c:\temp\testuser1 -j 8 -t mytable -h > myserver testdb > > where mytable is in testuser1 schema > > The dump completed fine but when I attempted to restore the table > using pg_restore to another database, it tried to create the table in > testuser1 schema. The restore failed since testuser1 schema does not > exist in the target database. When I created a testuser1 schema in the > target database, the restore worked fine. Since the dump toc is in > binary format, I could not make the change to reflect the new target > schema, testuser2. > > So, how should I go about restoring tables from one schema to a > different schema name? > > Thanks. > > Tiff > > Can you not simply rename the schema after importing it? Perhaps renaming an exiting version first, if necessary. Rename schema A to B; import schema A; rename A to C; rename B to A; --------------2D3579131E70EBB661D08F1F Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: 7bit


On 2/20/19 3:22 PM, Tiffany Thang wrote:
Hi Adrian,
I managed to backup my table in parallel using -Fd but I'm back to my original issue where I could not restore the table to a different schema.

For example,
I would like to backup testuser1.mytable and restore it to testuser2.mytable.

pg_dump -U testuser1 -Fd -f c:\temp\testuser1 -j 8 -t mytable -h myserver testdb

where mytable is in testuser1 schema

The dump completed fine but when I attempted to restore the table using pg_restore to another database, it tried to create the table in testuser1 schema. The restore failed since testuser1 schema does not exist in the target database. When I created a testuser1 schema in the target database, the restore worked fine. Since the dump toc is in binary format, I could not make the change to reflect the new target schema, testuser2.

So, how should I go about restoring tables from one schema to a different schema name?

Thanks.

Tiff


Can you not simply rename the schema after importing it? Perhaps renaming an exiting version first, if necessary. Rename schema A to B; import schema A; rename A to C; rename B to A;


--------------2D3579131E70EBB661D08F1F--