pg_dump & table space

Started by Luca Ferrarialmost 17 years ago5 messagesgeneral
Jump to latest
#1Luca Ferrari
fluca1978@infinito.it

Hi,
is there a way to dump an entire database which has a specific table space
without having in the sql file any reference to the tablespace? This can be
useful when moving the database from one machine to another (that does not use
the tablespace). Any way to achieve that with pg_dump?

Thanks,
Luca

#2John R Pierce
pierce@hogranch.com
In reply to: Luca Ferrari (#1)
Re: pg_dump & table space

Luca Ferrari wrote:

Hi,
is there a way to dump an entire database which has a specific table space
without having in the sql file any reference to the tablespace? This can be
useful when moving the database from one machine to another (that does not use
the tablespace). Any way to achieve that with pg_dump?

dump in ascii format, edit the resultant SQL file and remove any
references to the tablespace. this could probably be done with a perl
or sed script if the file is too large for a conventional text editor.

#3John R Pierce
pierce@hogranch.com
In reply to: John R Pierce (#2)
Re: pg_dump & table space

John R Pierce wrote:

Luca Ferrari wrote:

Hi,
is there a way to dump an entire database which has a specific table
space without having in the sql file any reference to the tablespace?
This can be useful when moving the database from one machine to
another (that does not use the tablespace). Any way to achieve that
with pg_dump?

dump in ascii format, edit the resultant SQL file and remove any
references to the tablespace. this could probably be done with a
perl or sed script if the file is too large for a conventional text
editor.

oh, dump the schema only first, edit that, then dump the data only to a
seperate dumpfile, thats probably simplest.

#4Tom Lane
tgl@sss.pgh.pa.us
In reply to: Luca Ferrari (#1)
Re: pg_dump & table space

Luca Ferrari <fluca1978@infinito.it> writes:

is there a way to dump an entire database which has a specific table space
without having in the sql file any reference to the tablespace? This can be
useful when moving the database from one machine to another (that does not use
the tablespace). Any way to achieve that with pg_dump?

Recent versions have

--no-tablespaces do not dump tablespace assignments

However, this is really just cosmetic, as the dump is set up like this:

SET default_tablespace = whatever;
CREATE TABLE whichever(...);

If tablespace 'whatever' doesn't exist, you'll get an error on the SET
but the CREATE will succeed anyway. (I guess this only works cleanly
if the destination machine has *none* of the source's tablespaces,
else things might get assigned to unexpected tablespaces. But it's
definitely possible to restore a dump without having the same
tablespaces.)

regards, tom lane

#5Alvaro Herrera
alvherre@2ndquadrant.com
In reply to: Tom Lane (#4)
Re: pg_dump & table space

Tom Lane wrote:

However, this is really just cosmetic, as the dump is set up like this:

SET default_tablespace = whatever;
CREATE TABLE whichever(...);

If tablespace 'whatever' doesn't exist, you'll get an error on the SET
but the CREATE will succeed anyway. (I guess this only works cleanly
if the destination machine has *none* of the source's tablespaces,
else things might get assigned to unexpected tablespaces. But it's
definitely possible to restore a dump without having the same
tablespaces.)

Maybe it would be better if the dump has a RESET default_tablespace
before the SET.

--
Alvaro Herrera http://www.CommandPrompt.com/
PostgreSQL Replication, Consulting, Custom Development, 24x7 support