Re: pg_dump is broken for partition tablespaces
Alvaro Herrera <alvherre@2ndquadrant.com>
From: Alvaro Herrera <alvherre@2ndquadrant.com>
To: Andres Freund <andres@anarazel.de>
Cc: David Rowley <david.rowley@2ndquadrant.com>, PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
Date: 2019-04-09T22:58:42Z
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
Commits
-
Make pg_dump emit ATTACH PARTITION instead of PARTITION OF (reprise)
- 6a781c4f5fec 11.4 landed
- 33a53130a894 12.0 landed
- 1eb8a5ea463d 10.9 landed
-
Fix tablespace inheritance for partitioned rels
- 87259588d0ab 12.0 landed
-
Make pg_dump emit ATTACH PARTITION instead of PARTITION OF
- a98c48debcd0 11.3 landed
- 5a191f697400 10.8 landed
- 3b23552ad8bb 12.0 landed
-
Make sure ALTER TABLE preserves index tablespaces.
- bd673e8e864a 10.0 cited