Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vgmyT-003qGc-1k for pgsql-general@arkaria.postgresql.org; Fri, 16 Jan 2026 16:47:02 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vgmyS-004Il0-1y for pgsql-general@arkaria.postgresql.org; Fri, 16 Jan 2026 16:47:00 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vgmyR-004Ikp-23 for pgsql-general@lists.postgresql.org; Fri, 16 Jan 2026 16:47:00 +0000 Received: from fout-a8-smtp.messagingengine.com ([103.168.172.151]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vgmyP-000mut-0J for pgsql-general@lists.postgresql.org; Fri, 16 Jan 2026 16:46:59 +0000 Received: from phl-compute-01.internal (phl-compute-01.internal [10.202.2.41]) by mailfout.phl.internal (Postfix) with ESMTP id 23E05EC00BB; Fri, 16 Jan 2026 11:46:57 -0500 (EST) Received: from phl-frontend-03 ([10.202.2.162]) by phl-compute-01.internal (MEProxy); Fri, 16 Jan 2026 11:46:57 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aklaver.com; h= cc:cc:content-transfer-encoding:content-type:content-type:date :date:from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to; s=fm1; t=1768582017; x=1768668417; bh=mdk/92r0zMMtMbASkmAHLvhdh2TqcuiYeDq/lq5aaR4=; b= VT7+LsR3evXxKnDXDhLKAeSozTwmCxujTmfsNAjAX7Cbes1tqzS4sbdbPPEzrz/r 62OA30Y37GDiOzB8bIdCsdowhLWXyg0r+50h+oRsOmwjvsQdaZrwolY6g/BVK20c t+4GjnEzWe5K+s/eQDfF0CrFgFoZ+j3OezvSsaoJPXkryf6MKYAlpr+OZb33BtDS C0BIbrdV/Vk+X/ceaiiPY3Jtqn+9f0czz+Os5GDQV4GjYOHJ9td8ubik5INlTLKk NGHRyagZf8ZtcQBOtJq2T+JZXjV/zxuEt3Ek4P8e2dv3gI9Jjr9VlcMApfvrrT0a b5cm9gQs3DYpX7nV6J/gFw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm2; t=1768582017; x= 1768668417; bh=mdk/92r0zMMtMbASkmAHLvhdh2TqcuiYeDq/lq5aaR4=; b=L nFAZdrXOGtQodaCcFd2MVhB+eoblA02isDUCz3dfabNztlFWEyqONkkjrMxI11g3 92apr4N9oZ1X+2gFblsS3zBNBNiBLgXMwkfBbQZxU/tlFSbnnsuX8PYJuTzt1nG4 75Gg1Cca3L7GWGkyBDjfXkaCEoLX+qPTz3C/oK99U1+9xMZnVs4E2rYiqZgM/Urv AhLSHYz9RD0HFy3zFs4G4aD2qHc63sL5QsFpHWc/LjN4QBqigD1Rrf65Zhc5+bIk T0epzwtYqNAfzZgk2fhJKoY85gaBxE89IHDwA39WFMIqjtzUV9q1wmI8asEqezSS vnDFRELN4nhfU+JwaNUCg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefgedrtddtgdduvdelgeehucetufdoteggodetrf dotffvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfurfetoffkrfgpnffqhgenuceu rghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujf gurhepkfffgggfuffvvehfhfgjtgfgsehtkeertddtvdejnecuhfhrohhmpeetughrihgr nhcumfhlrghvvghruceorggurhhirghnrdhklhgrvhgvrhesrghklhgrvhgvrhdrtghomh eqnecuggftrfgrthhtvghrnhepgfdufeekhfevfeelveeiueevhedvuddukeduvddvlefh ueeuieejtdeuvdevvdeunecuffhomhgrihhnpehpohhsthhgrhgvshhqlhdrohhrghenuc evlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpegrughrihgr nhdrkhhlrghvvghrsegrkhhlrghvvghrrdgtohhmpdhnsggprhgtphhtthhopeefpdhmoh guvgepshhmthhpohhuthdprhgtphhtthhopeguuggvvhhivghnnhgvsehgmhgrihhlrdgt ohhmpdhrtghpthhtohepmhgrrhgtvghfvghrnhejsehgmhgrihhlrdgtohhmpdhrtghpth htohepphhgshhqlhdqghgvnhgvrhgrlheslhhishhtshdrphhoshhtghhrvghsqhhlrdho rhhg X-ME-Proxy: Feedback-ID: i76984098:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 16 Jan 2026 11:46:56 -0500 (EST) Message-ID: <9d1c1ee2-7488-4efd-8451-5d5b3cabe7f2@aklaver.com> Date: Fri, 16 Jan 2026 08:46:56 -0800 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: Why does TRUNCATE require a special privilege? To: Dominique Devienne , Marcelo Fernandes Cc: pgsql-general@lists.postgresql.org References: Content-Language: en-US From: Adrian Klaver 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 On 1/16/26 02:32, Dominique Devienne wrote: > On Fri, Jan 16, 2026 at 10:13 AM Marcelo Fernandes wrote: >> From the documentation: >>> TRUNCATE quickly removes all rows from a set of tables. It has the same >>> effect as an unqualified DELETE on each table, but since it does not actually >>> scan the tables it is faster. >>> (...) >>> You must have the TRUNCATE privilege on a table to truncate it. >> >> Granted that TRUNCATE and DELETE are different operations under the hood, but >> why would the TRUNCATE operation require its own specific privilege rather than >> say, use the same privilege as the DELETE operation? > > It's kinda obvious, when you read the notes. > > 1) Not MVCC-safe. > 2) Do not fire TRIGGERs, thus breaking data-integrity It will not fire ON DELETE triggers, it will fire ON TRUNCATE triggers. > 3) "Viral" in the presence of FKs, i.e. related tables must also be TRUNCATEd Only if you add the CASCADE option, or TRUNCATE them in the same command. Otherwise it will fail. > > Just these 3 are HUGE departures from a DELETE. --DD I would add from: https://www.postgresql.org/docs/current/sql-truncate.html "TRUNCATE acquires an ACCESS EXCLUSIVE lock on each table it operates on, which blocks all other concurrent operations on the table. When RESTART IDENTITY is specified, any sequences that are to be restarted are likewise locked exclusively. If concurrent access to a table is required, then the DELETE command should be used instead." and "" When RESTART IDENTITY is specified, the implied ALTER SEQUENCE RESTART operations are also done transactionally; that is, they will be rolled back if the surrounding transaction does not commit. Be aware that if any additional sequence operations are done on the restarted sequences before the transaction rolls back, the effects of these operations on the sequences will be rolled back, but not their effects on currval(); that is, after the transaction currval() will continue to reflect the last sequence value obtained inside the failed transaction, even though the sequence itself may no longer be consistent with that. This is similar to the usual behavior of currval() after a failed transaction." > > -- Adrian Klaver adrian.klaver@aklaver.com