Omitting tablespace creation from pg_dumpall...

Started by Chander Ganesanalmost 20 years ago8 messagesgeneral
Jump to latest
#1Chander Ganesan
chander@otg-nc.com

I'd like to suggest that a feature be added to pg_dumpall to remove
tablespace definitions/creation from the output. While the inclusion is
important for backups - it's equally painful when attempting to migrate
data from a development to production database. Since PostgreSQL won't
create the directory that will contain the tablespace, the tablespace
creation will fail. Following that, any objects that are to be created
in that tablespace will fail (since the tablespace doesn't exist).

This means that one could potentially have to search and replace every
instance of a tablespace name in a dump file...

Perhaps a flag can be added to simply comment out tablespace definitions
(both the creation, and their use in CREATE DATABASE, etc. statements).
This would allow the statement to be uncommented if needed, and allow
DBA's to search for and modify tablespace names as needed...

I apologize if this has already been mentioned/suggested :-)
--
Chander Ganesan
The Open Technology Group
One Copley Parkway, Suite 210
Morrisville, NC 27560
Phone: 877-258-8987/919-463-0999
http://www.otg-nc.com

#2Tom Lane
tgl@sss.pgh.pa.us
In reply to: Chander Ganesan (#1)
Re: Omitting tablespace creation from pg_dumpall...

Chander Ganesan <chander@otg-nc.com> writes:

I'd like to suggest that a feature be added to pg_dumpall to remove
tablespace definitions/creation from the output. While the inclusion is
important for backups - it's equally painful when attempting to migrate
data from a development to production database. Since PostgreSQL won't
create the directory that will contain the tablespace, the tablespace
creation will fail. Following that, any objects that are to be created
in that tablespace will fail (since the tablespace doesn't exist).

If the above statements were actually true, it'd be a problem, but they
are not true. The dump only contains "SET default_tablespace = foo"
commands, which may themselves fail, but they won't prevent subsequent
CREATE TABLE commands from succeeding.

regards, tom lane

#3Chander Ganesan
chander@otg-nc.com
In reply to: Tom Lane (#2)
Re: Omitting tablespace creation from pg_dumpall...

Tom Lane wrote:

Chander Ganesan <chander@otg-nc.com> writes:

I'd like to suggest that a feature be added to pg_dumpall to remove
tablespace definitions/creation from the output. While the inclusion is
important for backups - it's equally painful when attempting to migrate
data from a development to production database. Since PostgreSQL won't
create the directory that will contain the tablespace, the tablespace
creation will fail. Following that, any objects that are to be created
in that tablespace will fail (since the tablespace doesn't exist).

If the above statements were actually true, it'd be a problem, but they
are not true. The dump only contains "SET default_tablespace = foo"
commands, which may themselves fail, but they won't prevent subsequent
CREATE TABLE commands from succeeding.

With PostgreSQL 8.1.4, if I do the following:

create tablespace test location '/srv/tblspc';
create database test with tablespace = test;

The pg_dumpall result will contain:
*****
CREATE TABLESPACE test OWNER postgres LOCATION '/srv/tblspc';
CREATE DATABASE test WITH TEMPLATE=template0 OWNER=postgres
ENCODING='utf8' TABLESPACE=test;

*****When this is executed on a load, the create database statement will
fail with a 'ERROR: tablespace test does not exist'. This error occurs
due to the fact that the initial create tablespace statement
fails...because the location isn't pre-created.

Perhaps the feature you mention (SET default_tablespace) is a feature
that is to be added post PostgreSQL 8.1 ?

The set default_tablespace method definitely sounds like the ideal
solution here...although its potentially misleading if a DBA doesn't
realize that the tablespace wasn't actually created...

Subsequent create statements inside the database will fail, since the
database create will fail.

--
Chander Ganesan
The Open Technology Group
One Copley Parkway, Suite 210
Morrisville, NC 27560
Phone: 877-258-8987/919-463-0999
http://www.otg-nc.com

Show quoted text

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 5: don't forget to increase your free space map settings

#4Florian Pflug
fgp@phlo.org
In reply to: Chander Ganesan (#3)
Re: Omitting tablespace creation from pg_dumpall...

Chander Ganesan wrote:

Tom Lane wrote:

Chander Ganesan <chander@otg-nc.com> writes:

I'd like to suggest that a feature be added to pg_dumpall to remove
tablespace definitions/creation from the output. While the inclusion
is important for backups - it's equally painful when attempting to
migrate data from a development to production database. Since
PostgreSQL won't create the directory that will contain the
tablespace, the tablespace creation will fail. Following that, any
objects that are to be created in that tablespace will fail (since
the tablespace doesn't exist).

If the above statements were actually true, it'd be a problem, but they
are not true. The dump only contains "SET default_tablespace = foo"
commands, which may themselves fail, but they won't prevent subsequent
CREATE TABLE commands from succeeding.

With PostgreSQL 8.1.4, if I do the following:

create tablespace test location '/srv/tblspc';
create database test with tablespace = test;

The pg_dumpall result will contain:
*****
CREATE TABLESPACE test OWNER postgres LOCATION '/srv/tblspc';
CREATE DATABASE test WITH TEMPLATE=template0 OWNER=postgres
ENCODING='utf8' TABLESPACE=test;

Hm.. I guess pg_dumpall is meant to create a identical clone of a
postgres "cluster" (Note that the term cluster refers to one
postgres-instance serving multiple databases, and _not_ to a cluster
in the high-availability sense). For moving a single database from one
machine to another, pg_dump might suit you more. With pg_dump, you
normally create the "new" database manually, and _afterwards_ restore
your dump into this database.

I'd say that pg_dumpall not supporting restoring into a different
tablespace is compareable to not supporting database renaming. Think
of pg_dumpall as equivalent to copying the data directory - only that
it works while the database is online, and supports differing
architectures on source and destination machine.

greetings, Florian Pflug

#5Bruce Momjian
bruce@momjian.us
In reply to: Florian Pflug (#4)
Re: Omitting tablespace creation from pg_dumpall...

Should pg_dumpall be using the "SET default_tablespace = foo" method as
well?

---------------------------------------------------------------------------

Florian G. Pflug wrote:

Chander Ganesan wrote:

Tom Lane wrote:

Chander Ganesan <chander@otg-nc.com> writes:

I'd like to suggest that a feature be added to pg_dumpall to remove
tablespace definitions/creation from the output. While the inclusion
is important for backups - it's equally painful when attempting to
migrate data from a development to production database. Since
PostgreSQL won't create the directory that will contain the
tablespace, the tablespace creation will fail. Following that, any
objects that are to be created in that tablespace will fail (since
the tablespace doesn't exist).

If the above statements were actually true, it'd be a problem, but they
are not true. The dump only contains "SET default_tablespace = foo"
commands, which may themselves fail, but they won't prevent subsequent
CREATE TABLE commands from succeeding.

With PostgreSQL 8.1.4, if I do the following:

create tablespace test location '/srv/tblspc';
create database test with tablespace = test;

The pg_dumpall result will contain:
*****
CREATE TABLESPACE test OWNER postgres LOCATION '/srv/tblspc';
CREATE DATABASE test WITH TEMPLATE=template0 OWNER=postgres
ENCODING='utf8' TABLESPACE=test;

Hm.. I guess pg_dumpall is meant to create a identical clone of a
postgres "cluster" (Note that the term cluster refers to one
postgres-instance serving multiple databases, and _not_ to a cluster
in the high-availability sense). For moving a single database from one
machine to another, pg_dump might suit you more. With pg_dump, you
normally create the "new" database manually, and _afterwards_ restore
your dump into this database.

I'd say that pg_dumpall not supporting restoring into a different
tablespace is compareable to not supporting database renaming. Think
of pg_dumpall as equivalent to copying the data directory - only that
it works while the database is online, and supports differing
architectures on source and destination machine.

greetings, Florian Pflug

---------------------------(end of broadcast)---------------------------
TIP 9: In versions below 8.0, the planner will ignore your desire to
choose an index scan if your joining column's datatypes do not
match

--
Bruce Momjian http://candle.pha.pa.us
EnterpriseDB http://www.enterprisedb.com

+ If your life is a hard drive, Christ can be your backup. +

#6Chander Ganesan
chander@otg-nc.com
In reply to: Florian Pflug (#4)
Re: Omitting tablespace creation from pg_dumpall...

Florian G. Pflug wrote:

Chander Ganesan wrote:

Tom Lane wrote:

Chander Ganesan <chander@otg-nc.com> writes:

I'd like to suggest that a feature be added to pg_dumpall to remove
tablespace definitions/creation from the output. While the
inclusion is important for backups - it's equally painful when
attempting to migrate data from a development to production
database. Since PostgreSQL won't create the directory that will
contain the tablespace, the tablespace creation will fail.
Following that, any objects that are to be created in that
tablespace will fail (since the tablespace doesn't exist).

If the above statements were actually true, it'd be a problem, but they
are not true. The dump only contains "SET default_tablespace = foo"
commands, which may themselves fail, but they won't prevent subsequent
CREATE TABLE commands from succeeding.

With PostgreSQL 8.1.4, if I do the following:

create tablespace test location '/srv/tblspc';
create database test with tablespace = test;

The pg_dumpall result will contain:
*****
CREATE TABLESPACE test OWNER postgres LOCATION '/srv/tblspc';
CREATE DATABASE test WITH TEMPLATE=template0 OWNER=postgres
ENCODING='utf8' TABLESPACE=test;

Hm.. I guess pg_dumpall is meant to create a identical clone of a
postgres "cluster" (Note that the term cluster refers to one
postgres-instance serving multiple databases, and _not_ to a cluster
in the high-availability sense). For moving a single database from one
machine to another, pg_dump might suit you more. With pg_dump, you
normally create the "new" database manually, and _afterwards_ restore
your dump into this database.

I'd say that pg_dumpall not supporting restoring into a different
tablespace is compareable to not supporting database renaming. Think
of pg_dumpall as equivalent to copying the data directory - only that
it works while the database is online, and supports differing
architectures on source and destination machine.

greetings, Florian Pflug

I understand why it's doing what it's doing - and I'm not disputing the
usefulness of it. I just think it might be good to have a flag that
allows the omission of the alternate tablespace usage (or set the
default instead of including it in the create db statement), since I can
see how the failures might become problematic in some environments.

--
Chander Ganesan
The Open Technology Group
One Copley Parkway, Suite 210
Morrisville, NC 27560
Phone: 877-258-8987/919-463-0999
http://www.otg-nc.com

#7Tom Lane
tgl@sss.pgh.pa.us
In reply to: Bruce Momjian (#5)
Re: Omitting tablespace creation from pg_dumpall...

Bruce Momjian <pgman@candle.pha.pa.us> writes:

Should pg_dumpall be using the "SET default_tablespace = foo" method as
well?

That would mean changing the semantics of CREATE DATABASE; currently it
copies the default tablespace from the template database, rather than
looking at default_tablespace. I'm unsure if that's a good idea or not.
None of the other properties of a database are handled that way.

regards, tom lane

#8Bruce Momjian
bruce@momjian.us
In reply to: Tom Lane (#7)
Re: [GENERAL] Omitting tablespace creation from pg_dumpall...

Tom Lane wrote:

Bruce Momjian <pgman@candle.pha.pa.us> writes:

Should pg_dumpall be using the "SET default_tablespace = foo" method as
well?

That would mean changing the semantics of CREATE DATABASE; currently it
copies the default tablespace from the template database, rather than
looking at default_tablespace. I'm unsure if that's a good idea or not.
None of the other properties of a database are handled that way.

Interesting distinction.

I have added a documentation and code comment patch for this.

--
Bruce Momjian http://candle.pha.pa.us
EnterpriseDB http://www.enterprisedb.com

+ If your life is a hard drive, Christ can be your backup. +

Attachments:

/bjm/difftext/x-diffDownload+17-10