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;
5959
6060/*
6161 * 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?
6365 */
6466CREATE OR REPLACE FUNCTION @extschema@.replace_hash_partition(
6567 old_partition REGCLASS,
66- new_partition REGCLASS)
68+ new_partition REGCLASS,
69+ lock_parent BOOL DEFAULT TRUE)
6770RETURNS REGCLASS AS
6871$$
6972DECLARE
8184 /* Parent relation */
8285 parent_relid := @extschema@.get_parent_of_partition(old_partition);
8386
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;
8694
8795 /* Acquire data modification lock (prevent further modifications) */
8896 PERFORM @extschema@.prevent_relation_modification(old_partition);
You can’t perform that action at this time.
0 commit comments