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 1kxumL-0002Ka-On for pgsql-general@arkaria.postgresql.org; Fri, 08 Jan 2021 16:38:22 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1kxumJ-00018w-Sd for pgsql-general@arkaria.postgresql.org; Fri, 08 Jan 2021 16:38:19 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kxumJ-00018p-J4 for pgsql-general@lists.postgresql.org; Fri, 08 Jan 2021 16:38:19 +0000 Received: from mout.gmx.net ([212.227.17.20]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kxumD-000876-MC for pgsql-general@postgresql.org; Fri, 08 Jan 2021 16:38:18 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1610123890; bh=qxdMRvO5JVwNr9s1hozCMVgpcawmYNqVYsRCrEtjpPg=; h=X-UI-Sender-Class:Subject:To:References:From:Date:In-Reply-To; b=C02lRBAwqSVUNvAB9W5Q7cd8fCNM7svJTBWHA1z1/Lvh5OvAeaShqw6SR6b1/SUiF ud92NoYfJZr4yU97i/7LcqJX1j7oguaIPpyxIfCT3NVTq574IgabSKXRdhZvHx+cYx itrnNJCubwNworFOR8BsTXTItklFZxbTj8hWNGMY= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from [192.168.178.20] ([83.171.164.188]) by mail.gmx.com (mrgmx104 [212.227.17.168]) with ESMTPSA (Nemesis) id 1N6KYb-1jryAd2KVt-016bi0 for ; Fri, 08 Jan 2021 17:38:10 +0100 Subject: Re: Suggestion: provide a "TRUNCATE PARTITION" command To: Postgres General References: <99277f39-f1a1-6da5-176c-3def058cf568@gmx.net> From: Thomas Kellerer Message-ID: <999c4e39-ec8d-35db-f77e-06361861fe4e@gmx.net> Date: Fri, 8 Jan 2021 17:38:10 +0100 User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; de; rv:1.8.1.21) Gecko/20090302 Thunderbird/2.0.0.21 Mnenhy/0.7.5.666 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: de-DE Content-Transfer-Encoding: quoted-printable X-Provags-ID: V03:K1:xP4NZUiLWaQtCycuFcpIkQIZZoaqIMNep8dmYCC9K7SeEzX/2Ck bcwr6fWopoy2pBs2sMH5Pxk6Z0dX1cbr64pRzQrRQXf/qdFGR5OqpMpK8yy/vtcvrtZi2Lp LI1qwJ8/yI1QtsN+z87S7XBzacxJM05b5gENPi9jukcqrZfXZrupNNSaPZ3QSImgYGC0uoH 5UYb+MBL3nxCeq20jKG0A== X-Spam-Flag: NO X-UI-Out-Filterresults: notjunk:1;V03:K0:FnjVRi/++6Y=:5TNw3ExLJZFk8H5QsUG/91 JqS5EEehsN2ZrqH/lcIAXIKXuea7t5Z8yqY7zMkMqAHQc3ztDtDAoEG2I1R9sVgP6L5bcaaGP X60kigRSwGO+do4tiFaKaLHjwzFfuniMR/Ibw/mOrROfO97Z00JwORWGFE3S7xa5zGMb6ECDo X86D9POOPxeMfaQrZfrcMX/w5myTNdbJeXD8p/AJ+Db5cQmLr3krzG8evoo2zUAt22EvDRcXg zGOVXzQR6cC0NGNK/WaCTOBAb5BosZ+kgtx2qswQAADTLP9l+Jg55kKujOEeozB1+6jq40ocz 34eLxTT8oVDRtbbxPdKV7b2XAdeGLIHWmSgIzgcksqZXtsqWws7SCXUiBTqrq684WRA0yqjkL C2G7lNrGJ3bUHRrwvsiwO/6mpFF+UTl3euJnGMSDEWAMdJ+Nse78G8rBVMs8yJisFmF2sRJ5a 2MKl3LyMrRErqyCWMVztLZ2UGKJ4x2VypUsml4m+bkKfgAaKmjBQINnM9Fj6ICBbHycbnzJBv 6RrsS0tNEY4+DffshotxHM39KLDYqrS2aRoKfauaGZw7FOn2kV00TNJZlVc2wRd0NbaLecgs3 vbgkgtczmPO4wIyE1u8niZInPsLp0z04/akbDUv9iVBS5g1wVrDjt6737QH71QyiyJBb0aQXe nLaeq9cO7YpcW/rykyx6JKpDKv/1mxCWavJ/3qPSg8Dah9MDAwmT60w+M0NdnicNHYu46yRex ZNS0eqfv+xNrtKKc/wTqtzshyHXvqtBHEqgYiNzpxE66zg2SQZLQ7jKSYFmy0eP28h2ioUAq+ zTCMdbh2HdL2j8SALDM3AjznTbZ4/JPJYo/XwWzqzO/BDDPubNygI6afy6VABYmtOq70On/r5 5rb7SgJL3XkEKJ0XXleA== List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Michael Lewis schrieb am 08.01.2021 um 16:32: > On Fri, Jan 8, 2021 at 2:36 AM Thomas Kellerer > wrote: > > Hello, > > I wonder if it made sense to add a "TRUNCATE PARTITION" command to P= ostgres? > > Especially during bulk loads it's more efficient to TRUNCATE a parti= tion if I know I want to replace all rows, rather than doing a DELETE. > > Currently this requires dynamic SQL which isn't always feasible (and= might get complicated quickly). > > So I was thinking that a new command to allow truncating partitions = by identifying the partitions by "value" rather by name might be helpful i= n that case. > > Something along the lines of: > > =C2=A0 =C2=A0 =C2=A0truncate partitions of base_table > =C2=A0 =C2=A0 =C2=A0for values in (...); > > If the IN part allowed for sub-queries then this could be used to ga= ther the partition keys from e.g. a staging table. > > > For me, it seems too easily error prone such that a single typo in > the IN clause may result in an entire partition being removed that > wasn't supposed to be targeted. I don't see how this is more dangerous then: delete from base_table where partition_key in (...); which would serve the same purpose, albeit less efficient. > Given the user still needs to > manually generate that list somehow, I don't see it as a huge effort > to query the partitions and run individual commands to truncate or > detach several partitions manually. Well, the list could come from e.g. a staging table, e.g. "for values IN (= select some_column from staging_table)"