pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Ian Barwick <ian.barwick@2ndquadrant.com>
To: Alex Williams <valenceshell@protonmail.com>
To: pgsql-general@lists.postgresql.org <pgsql-general@lists.postgresql.org>
Subject: Re: Restoring a database restores to unexpected tablespace
Date: Wed, 10 Jul 2019 11:35:15 +0900
Message-ID: <7fd8069f-a236-4e79-477c-7313ee416407@2ndquadrant.com> (raw)
In-Reply-To: <3YfH9uVTAd1a1GSxv8H2_mH4sPz_2a3NJgufLpjuMnMsIHd0P3uZ7GWFOD_Q9zgbX_ruyFPaRwdLw7Jncd5b7MokLdHYQMyogrhAIqnBR2o=@protonmail.com>
References: <3YfH9uVTAd1a1GSxv8H2_mH4sPz_2a3NJgufLpjuMnMsIHd0P3uZ7GWFOD_Q9zgbX_ruyFPaRwdLw7Jncd5b7MokLdHYQMyogrhAIqnBR2o=@protonmail.com>

On 7/10/19 2:56 AM, Alex Williams wrote:
> Hi,
> 
> Can someone point me in the right direction for this issue we are having -- our goal is to dump a database that is currently on a tablespace named data2 that we want to restore on the same server but on tablespace pg_default -- we tried other ways like:
> ALTER DATABASE "[database_name]" SET default_tablespace = [new_tablespace];
> alter table all in tablespace data2 set tablespace pg_default;
> 
> But we want to try it with a pgdump/psql.
> 
> To reproduce on our end (Server 9.5):
> 
> 1. create new database for the restore with the tablespace as pg_default
> 
> 2. Dump the source database (currently on data2 tablespace) with the following command:
> sudo -u postgres pg_dump mydatabase --no-owner --no-tablespaces | gzip  > mydatabase.gz
> 
> 3. Restore the database with this command:
> zcat /var/backup/db/mydatabase.gz |         sudo -H -u postgres         psql --quiet -e -c 'SET default_tablespace = pg_default;' -f - mydatabase_test > /tmp/mydatabase_test.log
> 
> What happens during the restore is that all tables are created on data2, not pg_default.
> 
> Any help would be greatly appreciated.

This should work.

Double-check each step to make sure nothing has been missed out somewhere, e.g.
in step 2 you create mydatabase.gz in the current working directory but in step 3 restore it
from an absolute filepath, which is a common cause of errors.

Also maybe try dumping an individual table definition (pg_dump --schema-only --table=sometablename ...) and check
exactly what's being dumped and how it gets restored.

Regards


Ian Barwick

-- 
  Ian Barwick                   https://www.2ndQuadrant.com/
  PostgreSQL Development, 24x7 Support, Training & Services





view thread (4+ messages)  latest in thread

Message-ID: <7fd8069f-a236-4e79-477c-7313ee416407@2ndquadrant.com>
Permalink:  ../7fd8069f-a236-4e79-477c-7313ee416407@2ndquadrant.com/
Also on:    postgresql.org/message-id/7fd8069f-a236-4e79-477c-7313ee416407@2ndquadrant.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: ian.barwick@2ndquadrant.com, valenceshell@protonmail.com
  Subject: Re: Restoring a database restores to unexpected tablespace
  In-Reply-To: <7fd8069f-a236-4e79-477c-7313ee416407@2ndquadrant.com>
  References: <3YfH9uVTAd1a1GSxv8H2_mH4sPz_2a3NJgufLpjuMnMsIHd0P3uZ7GWFOD_Q9zgbX_ruyFPaRwdLw7Jncd5b7MokLdHYQMyogrhAIqnBR2o=@protonmail.com> <7fd8069f-a236-4e79-477c-7313ee416407@2ndquadrant.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox