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 1oacFT-0001s1-4k for pgsql-hackers@arkaria.postgresql.org; Tue, 20 Sep 2022 12:21:11 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1oacFS-0002w7-0r for pgsql-hackers@arkaria.postgresql.org; Tue, 20 Sep 2022 12:21:10 +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 1oacFR-0002vx-Ll for pgsql-hackers@lists.postgresql.org; Tue, 20 Sep 2022 12:21:09 +0000 Received: from mail-lf1-x12d.google.com ([2a00:1450:4864:20::12d]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1oacFN-0000Qt-Cz for pgsql-hackers@lists.postgresql.org; Tue, 20 Sep 2022 12:21:09 +0000 Received: by mail-lf1-x12d.google.com with SMTP id a3so3438887lfk.9 for ; Tue, 20 Sep 2022 05:21:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date; bh=CN4BMf4q9+YEAI03S+5AlwuWYyZbzgsPO+Y9SxN65Ow=; b=Cgvw9nEgQ5A6APewQ0n3iSu+SugnaFyry9JJux8EMkwz/OwTwCm8E0xK5cyHId2L9u S+1dAtpwvBnr1OzKR/9Q8Fp9gxirqmeFP916i8GaMwmhwoQhiNC4+vO1wsxKAtLgSS2U /IITCejk5ugb355eSJNtzprNBF1flBAzpD90aFURgsUNHnmunHux1W7vMbWTUpL3NZhO +6ng1yzKK74rvFEdYdA6cRB5/VWEZGj4sJIH3nAXFTq2XVNm3d3ciUvtsMlu38ngH1r5 Lcl0Swspqhl//XC+uH9WFr8JC5SMvcZwvw9shdU/aEF//ZQoyQz9fd1hP+P5bcU+wZKp TBdg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date; bh=CN4BMf4q9+YEAI03S+5AlwuWYyZbzgsPO+Y9SxN65Ow=; b=o4Ug0lMhTi5sqZJs1HHIQ8JAIVTwouT5vY4EanzaV2/VwC2sDmJuyAYtJTZ10GVV0Z 1XJaXdgLZ5VCF//Hl7viOoEcCpUQb4jvdF9cQnNxxsmmJmab/gsIRPM4mkw/X8jdsxI0 ZAPFjEKuOHTb8+uh9UveL7JZMf+yfK0JjkKmvtYmt/lf7NS6L7efAk3yYJxz2ZkuJCER SRIb2NfyxyPiCJjxz6aFrBEaGaK59IP+9bArubQhwjpi7HjOj74K852SkWTVeNpuZaWI Pz1pJTIcS85cZ+25/qMzlVKHEh8x19Ij4veT7luxH7AOPQMo89g1OQi+mRMgquPVOZk9 2BGA== X-Gm-Message-State: ACrzQf2nY/zwjwpugUJGglCD5fiVJrne5XwpFmPGk3EA7cjUon95hRdz tHhkeCo0OOKwCc1y86HOidKPIK/bsie9Ex/bSlI= X-Google-Smtp-Source: AMsMyM4I8NqPpYUeeAGKfGELl818BfjQxjk2ZkiH4HmzoalLBKvuYfJYymbNber8W/TO8PgEpaTK27jtwcDzC/7aSVA= X-Received: by 2002:a05:6512:3f27:b0:497:270c:5004 with SMTP id y39-20020a0565123f2700b00497270c5004mr8786094lfa.321.1663676464005; Tue, 20 Sep 2022 05:21:04 -0700 (PDT) MIME-Version: 1.0 References: <163714495450.16056.3566953095730878367@malur.postgresql.org> <277c8df2-ce99-36b6-817a-ed510c7e8b82@postgrespro.ru> In-Reply-To: <277c8df2-ce99-36b6-817a-ed510c7e8b82@postgrespro.ru> From: Robert Haas Date: Tue, 20 Sep 2022 08:20:52 -0400 Message-ID: Subject: Re: Add SPLIT PARTITION/MERGE PARTITIONS commands To: Dmitry Koval Cc: PostgreSQL Hackers Content-Type: text/plain; charset="UTF-8" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Mon, Sep 19, 2022 at 4:42 PM Dmitry Koval wrote: > 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. Yeah, me neither. > 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). I think that a built-in DDL command can't really assume that the user won't modify anything. You'd have to take a ShareLock. But you might be able to have a CONCURRENTLY variant of the command that does the same kind of multi-transaction thing as, e.g., CREATE INDEX CONCURRENTLY. You would probably have to be quite careful about race conditions (e.g. you commit the first transaction and before you start the second one, someone drops or detaches the partition you were planning to merge or split). Might take some thought, but feels possibly doable. I've never been excited enough about this kind of thing to want to put a lot of energy into engineering it, because doing it "manually" feels so much nicer to me, and doubly so given that we now have ATTACH CONCURRENTLY and DETACH CONCURRENTLY, but it does seem like a thing some people would probably use and value. -- Robert Haas EDB: http://www.enterprisedb.com