From: Tom Lane <tgl@sss.pgh.pa.us>
To: Steven Lembark <lembark@wrkhors.com>
Cc: pgsql-general@lists.postgresql.org <pgsql-general@lists.postgresql.org>
Subject: Re: Move vs. copy table between databases that share a tablespace?
Date: Wed, 03 Apr 2019 10:10:54 -0400
Message-ID: <12183.1554300654@sss.pgh.pa.us> (raw)
In-Reply-To: <20190403081825.14dc71c9.lembark@wrkhors.com>
References: <20190403081825.14dc71c9.lembark@wrkhors.com>
Steven Lembark <lembark@wrkhors.com> 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
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: tgl@sss.pgh.pa.us, lembark@wrkhors.com
Subject: Re: Move vs. copy table between databases that share a tablespace?
In-Reply-To: <12183.1554300654@sss.pgh.pa.us>
References: <20190403081825.14dc71c9.lembark@wrkhors.com> <12183.1554300654@sss.pgh.pa.us>
* 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