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 1hl2SA-00045D-OG for pgsql-general@arkaria.postgresql.org; Wed, 10 Jul 2019 02:35:31 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hl2S9-00025f-1c for pgsql-general@arkaria.postgresql.org; Wed, 10 Jul 2019 02:35:29 +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 1hl2S8-00025V-Ix for pgsql-general@lists.postgresql.org; Wed, 10 Jul 2019 02:35:28 +0000 Received: from mail-pl1-x644.google.com ([2607:f8b0:4864:20::644]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hl2S1-0006GD-2B for pgsql-general@lists.postgresql.org; Wed, 10 Jul 2019 02:35:27 +0000 Received: by mail-pl1-x644.google.com with SMTP id c14so407137plo.0 for ; Tue, 09 Jul 2019 19:35:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=2ndquadrant-com.20150623.gappssmtp.com; s=20150623; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-language:content-transfer-encoding; bh=Bwmpwp8RHfYH2n41RmNYHKS8SKGjYXQXu63864oDCxc=; b=WCXJ9fJr8LHZZywO69YNt2n0sa7xIh0MLrgbP0cME5Vs+suearaORSxjyGRdSKO98k ZQc1XzDFIl9uBFhwb0XHsSL+JwfnGi2k5w9oLc6Le+mszUNMize8z2H76KCseOSpiu/X io7IzW3iaxJNmPuYeF4uVEbhqQpKkzHkRlbQX9OYl9OrdGk1zMPqBGLXA5H8fb647tVt e2xd2MkC8j2P7+kKPVitNjSxHDc2FUQqJC7QkSj8VvzqJI7tL6l5q2XCHjdkgnOYjjKZ SIBxQjRI4eH7Y+mYMWLFcBME5OoKQBBBLpjtWoh2Ka1dgKilQXHbyclZUcRqZQdkod4L nzcg== 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 :content-transfer-encoding; bh=Bwmpwp8RHfYH2n41RmNYHKS8SKGjYXQXu63864oDCxc=; b=DFT+fe+ytWywOze24QWb4DcjZBirDgyhQj0yI8kqIojB0+Jp4Weuk4ybzQUrJlTJmE 5HJbBjbrTtaE28NiuTDRtQ3324OCeXyr5h9sQiyH9YpvyzXzaTUyzRmsQIqn68Zn236a 4OkZ4K/lEm6dGUCk5hgA9q7DncoAhcSXnXZJcXLSlD4RALBcN9Q60IeJTnMNX2kOQ6sl G/BuD8vEgiP8KJKg2CxfJ7Sg/CvfbA/ddwpPwmhMOQCetFufib/vC2ULGZBYSUwrOuLn FXowK1ovj2755pi9jyKSBVe2Qb/LZLlOIaAp/YOQVEqBI8Ubi9LYUcBhRYIP21aVGqZA kUeA== X-Gm-Message-State: APjAAAX/l9PBZdkHBTi6zsFUvXGm3cbaNQ0PimvHRV+74ifMtNR6vs1Q JfI/FBkKcl0AIFg1GAxp8c/+fAFKb4k1uNl4GHPg9PwOrA33+T2+XDLfmI0M4lPrtIobBl3plbA IOESoSELIoqiMdPuJahUWM04JmemYGoNR8rTDtnumwCrVlEKtIhKZJcicYK3dlfARxS/8HLkcLi 82hw647nUZRtar64ZluKYt X-Google-Smtp-Source: APXvYqyDmdtQIhjIhbaQMHCkJTyfVCpKH08i4y5+7kOHE79+3B07Ea9bp/JSB2AycAqNxz73mglM+w== X-Received: by 2002:a17:902:7448:: with SMTP id e8mr35994126plt.85.1562726118152; Tue, 09 Jul 2019 19:35:18 -0700 (PDT) Received: from osaka.octopusnet (p274154-ipngn12401marunouchi.tokyo.ocn.ne.jp. [153.201.73.154]) by smtp.gmail.com with ESMTPSA id e13sm428233pff.45.2019.07.09.19.35.16 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 09 Jul 2019 19:35:17 -0700 (PDT) Subject: Re: Restoring a database restores to unexpected tablespace To: Alex Williams , "pgsql-general@lists.postgresql.org" References: <3YfH9uVTAd1a1GSxv8H2_mH4sPz_2a3NJgufLpjuMnMsIHd0P3uZ7GWFOD_Q9zgbX_ruyFPaRwdLw7Jncd5b7MokLdHYQMyogrhAIqnBR2o=@protonmail.com> From: Ian Barwick Message-ID: <7fd8069f-a236-4e79-477c-7313ee416407@2ndquadrant.com> Date: Wed, 10 Jul 2019 11:35:15 +0900 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.7.0 MIME-Version: 1.0 In-Reply-To: <3YfH9uVTAd1a1GSxv8H2_mH4sPz_2a3NJgufLpjuMnMsIHd0P3uZ7GWFOD_Q9zgbX_ruyFPaRwdLw7Jncd5b7MokLdHYQMyogrhAIqnBR2o=@protonmail.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk 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