File tree Expand file tree Collapse file tree 1 file changed +12
-4
lines changed Expand file tree Collapse file tree 1 file changed +12
-4
lines changed Original file line number Diff line number Diff line change @@ -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
CREATE OR REPLACE FUNCTION @extschema@.replace_hash_partition(
65
67
old_partition REGCLASS,
66
- new_partition REGCLASS)
68
+ new_partition REGCLASS,
69
+ lock_parent BOOL DEFAULT TRUE)
67
70
RETURNS REGCLASS AS
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);
You can’t perform that action at this time.
0 commit comments