Re: pg_dump is broken for partition tablespaces

From: Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>
To: Andres Freund <andres(at)anarazel(dot)de>
Cc: David Rowley <david(dot)rowley(at)2ndquadrant(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: pg_dump is broken for partition tablespaces
Date: 2019-04-09 22:58:42
Message-ID: 20190409225842.GA14993@alvherre.pgsql
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On 2019-Mar-06, Andres Freund wrote:

> I don't think the argument that the user intended to explicitly set a
> tablespace holds much water if it was just set via default_tablespace,
> rather than an explicit TABLESPACE. I think iff you really want
> something like this feature, you'd have to mark a partition's
> reltablespace as 0 unless an *explicit* assignment of the tablespace
> happened. In which case you also would need to explicitly emit a
> TABLESPACE for the partitioned table in pg_dump, to restore that.

Thinking more about this, I think you're wrong about the behavior under
nonempty default_tablespace. Quoth the fine manual:

default_tablespace:
[...]
This variable specifies the default tablespace in which to create
objects (tables and indexes) when a CREATE command does not explicitly specify
a tablespace.
The value is either the name of a tablespace, or an empty string to
specify using the default tablespace of the current database. [...]
https://www.postgresql.org/docs/11/runtime-config-client.html#RUNTIME-CONFIG-CLIENT-STATEMENT

What this says to me, if default_tablespace is set, and there is no
TABLESPACE clause, we should regard the default_tablespace just as if it
were an explicitly named tablespace. Note that the default setting of
default_tablespace is empty, meaning that tables are created in the
database tablespace.

Emerging behavior: default_tablespace is set to A, then partitioned
table T is created, then default_tablespace is changed to B. Any
partitions of T created afterwards still appear in tablespace A.

If you really intended for new partitions to be created in
default_tablespace (following future changes to that option), then you
should just leave default_tablespace as empty when creating T.

There is one deficiency that needs to be solved in order for this to
work fully: currently there is no way to reset "reltablespace" to 0.

Does that make sense?

--
Álvaro Herrera https://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Alvaro Herrera 2019-04-09 23:05:27 Re: pg_dump is broken for partition tablespaces
Previous Message Alvaro Herrera 2019-04-09 22:34:35 Re: pg_dump is broken for partition tablespaces