@@ -699,13 +699,13 @@ DECLARE
699699 v_part_name TEXT ;
700700 v_interval TEXT ;
701701BEGIN
702+ /* Prevent concurrent partition creation */
703+ PERFORM @extschema@.acquire_partitions_lock();
704+
702705 SELECT attname, range_interval INTO v_attname, v_interval
703706 FROM @extschema@.pathman_config WHERE relname::regclass = p_relation;
704707
705708 v_atttype := @extschema@.get_attribute_type_name(p_relation, v_attname);
706-
707- /* Prevent concurrent partition creation */
708- PERFORM @extschema@.acquire_partitions_lock();
709709
710710 EXECUTE format(' SELECT @extschema@.append_partition_internal($1, $2, $3, ARRAY[]::%s[])' , v_atttype)
711711 INTO v_part_name
@@ -721,8 +721,8 @@ BEGIN
721721 RETURN v_part_name;
722722
723723EXCEPTION WHEN others THEN
724- PERFORM @extschema@.release_partitions_lock();
725724 RAISE EXCEPTION ' % %' , SQLERRM, SQLSTATE;
725+ PERFORM @extschema@.release_partitions_lock();
726726END
727727$$
728728LANGUAGE plpgsql;
@@ -768,13 +768,13 @@ DECLARE
768768 v_part_name TEXT ;
769769 v_interval TEXT ;
770770BEGIN
771+ /* Prevent concurrent partition creation */
772+ PERFORM @extschema@.acquire_partitions_lock();
773+
771774 SELECT attname, range_interval INTO v_attname, v_interval
772775 FROM @extschema@.pathman_config WHERE relname::regclass = p_relation;
773776 v_atttype := @extschema@.get_attribute_type_name(p_relation, v_attname);
774777
775- /* Prevent concurrent partition creation */
776- PERFORM @extschema@.acquire_partitions_lock();
777-
778778 EXECUTE format(' SELECT @extschema@.prepend_partition_internal($1, $2, $3, ARRAY[]::%s[])' , v_atttype)
779779 INTO v_part_name
780780 USING p_relation, v_atttype, v_interval;
@@ -789,8 +789,8 @@ BEGIN
789789 RETURN v_part_name;
790790
791791EXCEPTION WHEN others THEN
792- PERFORM @extschema@.release_partitions_lock();
793792 RAISE EXCEPTION ' % %' , SQLERRM, SQLSTATE;
793+ PERFORM @extschema@.release_partitions_lock();
794794END
795795$$
796796LANGUAGE plpgsql;
0 commit comments