From 1daee0c503ded92d1504b5ec8c99401cee2994ed Mon Sep 17 00:00:00 2001 From: Koval Dmitry Date: Wed, 20 Apr 2022 21:14:25 +0300 Subject: [PATCH 1/2] [PGPRO-6538] Changed lock order The parent table is locked first and then are locked the partitions. --- src/pl_range_funcs.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/pl_range_funcs.c b/src/pl_range_funcs.c index 12c247ab..4465d36e 100644 --- a/src/pl_range_funcs.c +++ b/src/pl_range_funcs.c @@ -683,9 +683,6 @@ merge_range_partitions(PG_FUNCTION_ARGS) /* Extract partition Oids from array */ parts[i] = DatumGetObjectId(datums[i]); - /* Prevent modification of partitions */ - LockRelationOid(parts[i], AccessExclusiveLock); - /* Check if all partitions are from the same parent */ cur_parent = get_parent_of_partition(parts[i]); @@ -708,6 +705,10 @@ merge_range_partitions(PG_FUNCTION_ARGS) /* Prevent changes in partitioning scheme */ LockRelationOid(parent, ShareUpdateExclusiveLock); + /* Prevent modification of partitions */ + for (i = 0; i < nparts; i++) + LockRelationOid(parts[i], AccessExclusiveLock); + /* Emit an error if it is not partitioned by RANGE */ prel = get_pathman_relation_info(parent); shout_if_prel_is_invalid(parent, prel, PT_RANGE); From 66543e768f7b9a7de6844f9bb0780a253ddc2823 Mon Sep 17 00:00:00 2001 From: Koval Dmitry Date: Thu, 21 Apr 2022 15:25:13 +0300 Subject: [PATCH 2/2] [PGPRO-6538] Skip non-existing relations for Citus compatibility (issue #247) --- src/utility_stmt_hooking.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/utility_stmt_hooking.c b/src/utility_stmt_hooking.c index 89649e0d..35786092 100644 --- a/src/utility_stmt_hooking.c +++ b/src/utility_stmt_hooking.c @@ -114,7 +114,11 @@ is_pathman_related_copy(Node *parsetree) (copy_stmt->is_from ? PATHMAN_COPY_WRITE_LOCK : PATHMAN_COPY_READ_LOCK), - false); + true); + + /* Skip relation if it does not exist (for Citus compatibility) */ + if (!OidIsValid(parent_relid)) + return false; /* Check that relation is partitioned */ if (has_pathman_relation_info(parent_relid))