Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oaNbJ-00046f-JZ for pgsql-hackers@arkaria.postgresql.org; Mon, 19 Sep 2022 20:42:46 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1oaNbI-0006Cs-CA for pgsql-hackers@arkaria.postgresql.org; Mon, 19 Sep 2022 20:42:44 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oaNbH-0006Cj-Sb for pgsql-hackers@lists.postgresql.org; Mon, 19 Sep 2022 20:42:44 +0000 Received: from mail.postgrespro.ru ([93.174.131.139]) by magus.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1oaNbE-0000kL-Ux for pgsql-hackers@lists.postgresql.org; Mon, 19 Sep 2022 20:42:43 +0000 Received: from [192.168.28.32] (cyclops.postgrespro.ru [93.174.131.138]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client did not present a certificate) by mail.postgrespro.ru (Postfix) with ESMTPSA id ACEDE21C3BA1; Mon, 19 Sep 2022 23:42:39 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=postgrespro.ru; s=mail; t=1663620159; bh=wpBAkqi/6QTdBcXUP8xdZ26HZw96wT7LMfxeoiIGkxE=; h=Date:Subject:To:Cc:References:From:In-Reply-To; b=YQUl2U5W/JLnnwxrpDbmTtgcmgGmkaNQWNs8glQJ1/kOfAas3Do8CqBOTL8M31Iao SJ4gVSKjfT2x+KLkGgJRGFjPG6iFqPg+M2DU+pN9dGf35eAc9lVIcz6Wpc+RhrldLj GIvILcAoV5HSBMwcIj6drlMCFmrU4XnFYgOJE6hA= Message-ID: <277c8df2-ce99-36b6-817a-ed510c7e8b82@postgrespro.ru> Date: Mon, 19 Sep 2022 23:42:38 +0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Thunderbird/91.13.0 Subject: Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Content-Language: en-US To: Robert Haas Cc: PostgreSQL Hackers References: <163714495450.16056.3566953095730878367@malur.postgresql.org> From: Dmitry Koval In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Thanks for comments and advice! I thought about this problem and discussed about it with colleagues. Unfortunately, I don't know of a good general solution. 19.09.2022 22:56, Robert Haas пишет: > If you know that a certain partition is not changing, and you would > like to split it, you can create two or more new standalone tables and > populate them from the original partition using INSERT .. SELECT. Then > you can BEGIN a transaction, DETACH the existing partitions, and > ATTACH the replacement ones. By doing this, you take an ACCESS > EXCLUSIVE lock on the partitioned table only for a brief period. The > same kind of idea can be used to merge partitions. But for specific situation like this (certain partition is not changing) we can add CONCURRENTLY modifier. Our DDL query can be like ALTER TABLE...SPLIT PARTITION [CONCURRENTLY]; With CONCURRENTLY modifier we can lock partitioned table in ShareUpdateExclusiveLock mode and split partition - in AccessExclusiveLock mode. So we don't lock partitioned table in AccessExclusiveLock mode and can modify other partitions during SPLIT operation (except split partition). If smb try to modify split partition, he will receive error "relation does not exist" at end of operation (because split partition will be drop). -- With best regards, Dmitry Koval Postgres Professional: http://postgrespro.com