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.94.2) (envelope-from ) id 1u4L3e-000sNk-5U for pgsql-general@arkaria.postgresql.org; Mon, 14 Apr 2025 14:45:10 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1u4L3b-001VsX-M1 for pgsql-general@arkaria.postgresql.org; Mon, 14 Apr 2025 14:45:08 +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.94.2) (envelope-from ) id 1u4L3b-001VsP-9t for pgsql-general@lists.postgresql.org; Mon, 14 Apr 2025 14:45:08 +0000 Received: from sss.pgh.pa.us ([68.162.161.243]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1u4L3Y-0002w8-2h for pgsql-general@lists.postgresql.org; Mon, 14 Apr 2025 14:45:07 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 53EEj1HO1257960; Mon, 14 Apr 2025 10:45:01 -0400 From: Tom Lane To: Dimitrios Apostolou cc: pgsql-general@lists.postgresql.org Subject: Re: TRUNCATE ONLY with foreign keys and triggers disabled In-reply-to: References: Comments: In-reply-to Dimitrios Apostolou message dated "Mon, 14 Apr 2025 12:57:04 +0200" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <1257958.1744641901.1@sss.pgh.pa.us> Date: Mon, 14 Apr 2025 10:45:01 -0400 Message-ID: <1257959.1744641901@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Dimitrios Apostolou writes: > While doing TRUNCATE ONLY I get: > ERROR: cannot truncate a table referenced in a foreign key constraint > But in my case the table to be truncated is already empty, and the > TRIGGERS are disabled in all tables. IIRC, it will let you do it if you truncate both the referenced and referencing tables in the same command. The state of the triggers is not material to this, since TRUNCATE doesn't fire them anyway. regards, tom lane