@@ -59,11 +59,14 @@ SET client_min_messages = WARNING;
59
59
60
60
/*
61
61
* Replace hash partition with another one. It could be useful in case when
62
- * someone wants to attach foreign table as a partition
62
+ * someone wants to attach foreign table as a partition.
63
+ *
64
+ * lock_parent - should we take an exclusive lock?
63
65
*/
64
66
CREATEOR REPLACE FUNCTION @extschema@.replace_hash_partition(
65
67
old_partitionREGCLASS,
66
- new_partitionREGCLASS)
68
+ new_partitionREGCLASS,
69
+ lock_parentBOOL DEFAULT TRUE)
67
70
RETURNS REGCLASSAS
68
71
$$
69
72
DECLARE
81
84
/* Parent relation*/
82
85
parent_relid := @extschema@.get_parent_of_partition(old_partition);
83
86
84
- /* Acquire lock on parent*/
85
- PERFORM @extschema@.lock_partitioned_relation(parent_relid);
87
+ IF lock_parent THEN
88
+ /* Acquire data modification lock (prevent further modifications)*/
89
+ PERFORM @extschema@.prevent_relation_modification(parent_relid);
90
+ ELSE
91
+ /* Acquire lock on parent*/
92
+ PERFORM @extschema@.lock_partitioned_relation(parent_relid);
93
+ END IF;
86
94
87
95
/* Acquire data modification lock (prevent further modifications)*/
88
96
PERFORM @extschema@.prevent_relation_modification(old_partition);