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 1hBgbV-0000XP-Ob for pgsql-general@arkaria.postgresql.org; Wed, 03 Apr 2019 14:11:01 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hBgbU-00073V-65 for pgsql-general@arkaria.postgresql.org; Wed, 03 Apr 2019 14:11:00 +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 1hBgbT-000706-Nr for pgsql-general@lists.postgresql.org; Wed, 03 Apr 2019 14:10:59 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hBgbQ-0002VK-Tn for pgsql-general@lists.postgresql.org; Wed, 03 Apr 2019 14:10:58 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id x33EAscO012184; Wed, 3 Apr 2019 10:10:54 -0400 From: Tom Lane To: Steven Lembark cc: "pgsql-general@lists.postgresql.org" Subject: Re: Move vs. copy table between databases that share a tablespace? In-reply-to: <20190403081825.14dc71c9.lembark@wrkhors.com> References: <20190403081825.14dc71c9.lembark@wrkhors.com> Comments: In-reply-to Steven Lembark message dated "Wed, 03 Apr 2019 08:18:25 -0500" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <12182.1554300653.1@sss.pgh.pa.us> Date: Wed, 03 Apr 2019 10:10:54 -0400 Message-ID: <12183.1554300654@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Steven Lembark writes: > Trying to find a way of moving a large table between databases > in the same cluster. There is not sufficient space to copy the > contents -- the dedicated tablespace that fits the beastie is > on an 80% full disk. > Given that the two databases live in the same cluster and have > the owner & the tablespace in common, is there any way to move > the contents without a dump & reload? In principle you could do that; it's more or less the same thing that pg_upgrade --link does. But doing it by hand is not officially supported and there are multiple ways to shoot yourself in the foot. Basically the idea is to create an identically-declared table in the target database, and then swap the physical files of the two tables. Read https://www.postgresql.org/docs/current/storage.html --- *carefully* --- to find out how to identify the right physical files. A few foot-guns I can think of: * Making an identically-declared table might be more complicated than you'd think, if the table has had any ALTERs done to its rowtype over its lifetime (ALTER DROP COLUMN is a particularly critical bit of history here). A good way to proceed is to see what "pg_dump -s --binary_upgrade" does to recreate the table. * Shut down the postmaster while doing the actual file movement, else you'll get burnt by cached page copies. * Don't forget to move all the associated files, including multiple segment files (I'm sure you have a lot, if this table is big enough to be worth troubling over), and FSM and VM files. * The indexes on the table also need to be moved through the same type of process. I'd strongly counsel practicing on a test setup before you try to do this to your live data. Oh: and you have a backup, I trust. regards, tom lane