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 1vgrAS-005VyC-0F for pgsql-general@arkaria.postgresql.org; Fri, 16 Jan 2026 21:15:40 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vgrAR-00548f-0Y for pgsql-general@arkaria.postgresql.org; Fri, 16 Jan 2026 21:15:39 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vgrAQ-00548X-2e for pgsql-general@lists.postgresql.org; Fri, 16 Jan 2026 21:15:39 +0000 Received: from mail-oa1-x43.google.com ([2001:4860:4864:20::43]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1vgrAO-000srf-2x for pgsql-general@lists.postgresql.org; Fri, 16 Jan 2026 21:15:38 +0000 Received: by mail-oa1-x43.google.com with SMTP id 586e51a60fabf-4045e70f36eso608865fac.1 for ; Fri, 16 Jan 2026 13:15:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1768598134; cv=none; d=google.com; s=arc-20240605; b=LfS7mSom1/5J/8ERut1JxVOwaKS8g9d6ukI9tbzxuZ+2eHpZkSW2DilqegMTaArgXa +u4O4UnQWxRDkQK9K7fchh5oXF0cw+4Z40i7tUHEfFLdfk47iggIS3DcsLBBh237APW0 QuCKGMpj2deL5JASX5fk0rXBdK0d53H0CptVCHiN1DiXFVa/Gj2XOHvVIHyzmnSjCWmI 21p9wN+wFqlP9Frs700k6JcL4c1rn8LsWU2i+9OyZV1mhILplyY+v+IUjYbD7jGOBrb2 8KAq8cz0TH/fe/DV8g3apvJAlheHkCpKljilO6BrZvx/fVGB3bKzHgwOaA8c65isvsuZ q9bg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=izphAJ8LO26aDHk16WSZ6UeOCBTvLaWR3x4Sz5z1o5o=; fh=VzlswxNPi346VqbvZrj7oImb79k7xKWAGxNLJGO19Sc=; b=KmFcuisnqo+xzvAR7ek+mCnV85V9+1ZiaBvVLHLhDZcVq49I7JmAWamDyTgTr4KnAb /N8AWQqPOGUX+cLMaO53RoFKVchQKK847VX8sxMdRpfkgByfsGlyuixf/JJ71CfjmaI8 dFObG9yIgu/4CevypMEDNkkno6bsmdVPcGRy+1tdHi1jPhThkRmhUnRfw1Xbj3c8eIuR bT1S0CYHEwAH5rNNDjPl/ahE2QOYEoSdpnkZFdyF3EzNJgFPM70tgSeDGfNWtC4vttvi QVfDc0l7qagL95IRQwzPAPQX89FLKzumdTmbVuOHALQ40XrkZOLvpGPyg7hL+8gUC8J0 ag7w==; darn=lists.postgresql.org ARC-Authentication-Results: i=1; mx.google.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1768598134; x=1769202934; darn=lists.postgresql.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=izphAJ8LO26aDHk16WSZ6UeOCBTvLaWR3x4Sz5z1o5o=; b=W8LSoPsufcgB4YUBKWv3Uh79m/S/zX/DnArGC99/UYOI9m9MbVChC1/Xfgh0GMOxJL fDZXSQSSwDyRGrBr9fttS38irv8juFJ1miYOSm71uJ+e30YJ35zA/eeQgm1xXyXTehut GJCSYvZfs2+fvVugwzDCGO1AngBdbQP26139A3PewGnBGoBdPl8avO382u6HQbgMMO5U 7GNcEzRbHwRCrbAgz7jxsWelWHUKVWxNSveGxy2h2XnOov+ujqUCaqr6dRXkBCJlkWKr DaeWDPvg/Xa13XEaYxLRe0nmQkIZr+4ObbshYZU1OCHyLeRZhuysk+wDxJfpxPA95l0U 700Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1768598134; x=1769202934; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=izphAJ8LO26aDHk16WSZ6UeOCBTvLaWR3x4Sz5z1o5o=; b=O+Lzb71zwgMbWLX3lIOPFuAlS6KuZRGcH7lurksgEOZtnIgJ+aTBrdUrvDoHD9ihPa qqL7T8dYLWGLls/nTT2/d3K4dSDh3rttkMa6Jja5AOuPjrSAmKZhp+v/o7RAuLqlEBIn QFI33BzuBF6kw+acVry7e3dpVseGumw1jms85ydGMZ/LhFafSWcsd7X4mCElyHoUX6Km 4qsW7bTMZ68aVANLKU/YUb4jqCB1/L3sCdRsvvZudCKXFdZ66GF/r/g3HjAgl3utxRiX 08RHrT97BwNVem0Sh4Mez2CLz7o8nTncc/96zy7OCTH+YJBQ+boMI3Pgr0wNKcdiZ5Bl /xLg== X-Forwarded-Encrypted: i=1; AJvYcCW9vNmAfA5uDRoHlz5CkruxZXlx9aZM/AIj6ajdGZXBmAOZGXyBi1xtzRelpDQtwtiLFIC6vus6DKjzjJey@lists.postgresql.org X-Gm-Message-State: AOJu0Yx3UizwWuB+gZBkyNzHHrz5CPEUB4Ps1LATrwJoiMkm675JsYIc R9FBrkVpF8xWHfuh7ZWVsIM/WneXcv3yAXfikkr71P5SaeGpgB0F0NNJL0c5yPVBUXXaRssPYWb g1ZJg7zR/QS7DNc+/ClDO3LUw3EpA5I0= X-Gm-Gg: AY/fxX6E9Tt2Ik+Iqwo0mrmaLLL6ksia7g9q2CB9SiiVKDBDn2VFXo57Dt0viq7yJpG peQx246tJTqrcborm/hEkGWUfrXq5jZtPfQzzzoOo02fEN8I7ZeoB+FkTAIMV6gbWI+1ng4qqO7 n5KrRQUliyN05lsaojGEQJRs/uP+6HTdXXnYy7xxTpAHRFTM5HFIgw0pad8nkSzs7irUfNwL82E vFdrNjHxOuas96dk3/FdLgBp9yBlpCYFAAE09Tu0lwda8U7oHw3YRlLRpBKvzMKN3qJA6Y= X-Received: by 2002:a4a:e905:0:b0:65f:66c5:c3e with SMTP id 006d021491bc7-66117973443mr1870943eaf.22.1768598129567; Fri, 16 Jan 2026 13:15:29 -0800 (PST) MIME-Version: 1.0 References: <9d1c1ee2-7488-4efd-8451-5d5b3cabe7f2@aklaver.com> In-Reply-To: <9d1c1ee2-7488-4efd-8451-5d5b3cabe7f2@aklaver.com> From: Marcelo Fernandes Date: Sat, 17 Jan 2026 10:15:18 +1300 X-Gm-Features: AZwV_QhTL7RgLVpNmaZN2XI6zj8fjhBslMXTfGQ1bfi3pGGK8kZ4CBKtAmxB8io Message-ID: Subject: Re: Why does TRUNCATE require a special privilege? To: Adrian Klaver Cc: Dominique Devienne , pgsql-general@lists.postgresql.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Those operations do different things, sure. But from a roles/privilege framework perspective, why would you want to giv= e certain users the DELETE privilege whereas others you want to give them only the TRUNCATE privilege? Are we saying to a user that "You need a different level of privilege becau= se you are about to cause a MVCC-unsafe operation?". Or is the privilege framework simply ruling "Do different things, have different permissions"? Marcelo. On Sat, Jan 17, 2026 at 5:46=E2=80=AFAM Adrian Klaver wrote: > > On 1/16/26 02:32, Dominique Devienne wrote: > > On Fri, Jan 16, 2026 at 10:13=E2=80=AFAM Marcelo Fernandes wrote: > >> From the documentation: > >>> TRUNCATE quickly removes all rows from a set of tables. It has the sa= me > >>> 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 ho= od, but > >> why would the TRUNCATE operation require its own specific privilege ra= ther 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 TRU= NCATEd > > 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