1
0
mirror of https://github.com/postgres/postgres.git synced 2025-05-29 16:21:20 +03:00
Alvaro Herrera ebfe2dbd6b
Prevent drop of tablespaces used by partitioned relations
When a tablespace is used in a partitioned relation (per commits
ca4103025dfe in pg12 for tables and 33e6c34c3267 in pg11 for indexes),
it is possible to drop the tablespace, potentially causing various
problems.  One such was reported in bug #16577, where a rewriting ALTER
TABLE causes a server crash.

Protect against this by using pg_shdepend to keep track of tablespaces
when used for relations that don't keep physical files; we now abort a
tablespace if we see that the tablespace is referenced from any
partitioned relations.

Backpatch this to 11, where this problem has been latent all along.  We
don't try to create pg_shdepend entries for existing partitioned
indexes/tables, but any ones that are modified going forward will be
protected.

Note slight behavior change: when trying to drop a tablespace that
contains both regular tables as well as partitioned ones, you'd
previously get ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE and now you'll
get ERRCODE_DEPENDENT_OBJECTS_STILL_EXIST.  Arguably, the latter is more
correct.

It is possible to add protecting pg_shdepend entries for existing
tables/indexes, by doing
  ALTER TABLE ONLY some_partitioned_table SET TABLESPACE pg_default;
  ALTER TABLE ONLY some_partitioned_table SET TABLESPACE original_tablespace;
for each partitioned table/index that is not in the database default
tablespace.  Because these partitioned objects do not have storage, no
file needs to be actually moved, so it shouldn't take more time than
what's required to acquire locks.

This query can be used to search for such relations:
SELECT ... FROM pg_class WHERE relkind IN ('p', 'I') AND reltablespace <> 0

Reported-by: Alexander Lakhin <exclusion@gmail.com>
Discussion: https://postgr.es/m/16577-881633a9f9894fd5@postgresql.org
Author: Álvaro Herrera <alvherre@alvh.no-ip.org>
Reviewed-by: Michael Paquier <michael@paquier.xyz>
2021-01-14 15:32:14 -03:00
..
2020-07-05 15:37:57 +02:00
2020-09-10 14:15:26 +02:00
2020-11-07 12:26:24 +01:00
2020-10-26 19:17:05 -04:00
2020-02-26 13:05:30 -08:00
2020-03-29 11:15:11 +02:00
2018-10-11 11:43:56 -07:00
2020-11-25 09:49:00 +01:00
2019-09-08 10:27:29 +02:00
2020-10-19 19:28:54 +03:00
2020-11-21 08:26:20 +01:00
2020-07-18 22:43:35 +09:00
2020-12-01 14:36:30 +02:00
2020-12-20 07:20:33 +03:00
2020-10-19 13:48:00 +02:00
2020-06-07 13:18:36 +02:00
2021-01-13 11:07:37 +01:00
2020-07-18 22:43:35 +09:00
2019-10-25 20:39:41 +02:00
2020-07-18 22:43:35 +09:00
2020-10-19 19:28:54 +03:00
2020-12-01 14:36:30 +02:00
2021-01-02 13:06:25 -05:00
2019-09-08 10:27:29 +02:00
2021-01-02 13:06:25 -05:00
2020-10-19 19:28:54 +03:00
2020-10-19 19:28:54 +03:00
2021-01-05 14:26:37 -05:00
2020-10-19 19:28:54 +03:00
2020-08-28 08:19:12 +02:00
2020-12-23 09:33:20 -05:00
2020-12-23 09:33:20 -05:00
2020-12-23 09:33:20 -05:00
2020-11-19 09:32:47 +01:00
2020-06-07 17:16:30 -04:00
2020-06-07 17:16:30 -04:00
2020-10-19 19:28:54 +03:00
2020-10-19 19:28:54 +03:00
2019-09-08 10:27:29 +02:00
2019-08-13 08:40:17 +02:00
2019-03-27 23:10:23 +01:00
2019-09-08 10:27:29 +02:00

<!-- doc/src/sgml/README.links -->

Linking within DocBook documents can be confusing, so here is a summary:


Intra-document Linking
----------------------

<xref>
	use to get chapter/section number from the title of the target
	link, or xreflabel if defined at the target, or refentrytitle if target
        is a refentry;  has no close tag
	http://www.oasis-open.org/docbook/documentation/reference/html/xref.html

linkend=
	controls the target of the link/xref, required

endterm=
	for <xref>, allows the text of the link/xref to be taken from a
	different link target title

<link>
	use to supply text for the link, only uses linkend, requires </link>
	http://www.oasis-open.org/docbook/documentation/reference/html/link.html


External Linking
----------------

<ulink>
	like <link>, but uses a URL (not a document target);  requires
	</ulink>; if no text is specified, the URL appears as the link
	text
	http://www.oasis-open.org/docbook/documentation/reference/html/ulink.html

url=
	used by <ulink> to specify the URL, required


Guidelines
----------

- For an internal link, if you want to supply text, use <link>, else
  <xref>.

- Specific nouns like GUC variables, SQL commands, and contrib modules
  usually have xreflabels.

- For an external link, use <ulink>, with or without link text.

- xreflabels added to tags prevent the chapter/section for id's from being
  referenced;  only the xreflabel is accessible.  Therefore, use xreflabels
  only when linking is common, and chapter/section information is unneeded.