diff options
author | Michael Paquier <michael@paquier.xyz> | 2018-11-05 11:04:02 +0900 |
---|---|---|
committer | Michael Paquier <michael@paquier.xyz> | 2018-11-05 11:04:02 +0900 |
commit | dc3e436b191a8f8d6f35fad952dd3dc314ccabf9 (patch) | |
tree | 892ae581aef96ed59ec942bea0df3544d5a2bfef /src/backend/commands/tablecmds.c | |
parent | 4bc772e2afa55f26734ff3fbdf27601db030b7e5 (diff) | |
download | postgresql-dc3e436b191a8f8d6f35fad952dd3dc314ccabf9.tar.gz postgresql-dc3e436b191a8f8d6f35fad952dd3dc314ccabf9.zip |
Block creation of partitions with open references to its parent
When a partition is created as part of a trigger processing, it is
possible that the partition which just gets created changes the
properties of the table the executor of the ongoing command relies on,
causing a subsequent crash. This has been found possible when for
example using a BEFORE INSERT which creates a new partition for a
partitioned table being inserted to.
Any attempt to do so is blocked when working on a partition, with
regression tests added for both CREATE TABLE PARTITION OF and ALTER
TABLE ATTACH PARTITION.
Reported-by: Dmitry Shalashov
Author: Amit Langote
Reviewed-by: Michael Paquier, Tom Lane
Discussion: https://postgr.es/m/15437-3fe01ee66bd1bae1@postgresql.org
Backpatch-through: 10
Diffstat (limited to 'src/backend/commands/tablecmds.c')
-rw-r--r-- | src/backend/commands/tablecmds.c | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index d271a50fc7f..6048334c755 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -1994,6 +1994,14 @@ MergeAttributes(List *schema, List *supers, char relpersistence, relation = heap_openrv(parent, AccessExclusiveLock); /* + * Check for active uses of the parent partitioned table in the + * current transaction, such as being used in some manner by an + * enclosing command. + */ + if (is_partition) + CheckTableNotInUse(relation, "CREATE TABLE .. PARTITION OF"); + + /* * We do not allow partitioned tables and partitions to participate in * regular inheritance. */ |