Re: TRUNCATE ONLY with foreign keys and triggers disabled - Mailing list pgsql-general

From Adrian Klaver
Subject Re: TRUNCATE ONLY with foreign keys and triggers disabled
Date
Msg-id 3b2467c2-3af2-438a-87e6-81e6653ffd0e@aklaver.com
Whole thread Raw
In response to Re: TRUNCATE ONLY with foreign keys and triggers disabled  (Dimitrios Apostolou <jimis@gmx.net>)
Responses Re: TRUNCATE ONLY with foreign keys and triggers disabled
List pgsql-general
On 4/14/25 08:20, Dimitrios Apostolou wrote:
> On Mon, 14 Apr 2025, Adrian Klaver wrote:
> 
>> On 4/14/25 08:07, Laurenz Albe wrote:
>>>  On Mon, 2025-04-14 at 17:05 +0200, Dimitrios Apostolou wrote:
>>>>  I meant the *referencing* table has just been
>>>>  populated. I'm trying to delete the *referenced* table and I get the
>>>>  error.
>>>
>>>  That would break the foreign key constraint, right?
>>>  PostgreSQL cannot allow that.
>>
>> I believe the OP is disabling all triggers including system ones if I 
>> follow
>> correctly and possibly running a foul of;
>>
>> https://www.postgresql.org/docs/current/sql-altertable.html
>>
>> " Disabling or enabling internally generated constraint triggers requires
>> superuser privileges; it should be done with caution since of course the
>> integrity of the constraint cannot be guaranteed if the triggers are not
>> executed."
> 
> Exactly that. I learned this from pg_restore --disable-triggers, as a way
> to speed-up insertion.
> 
> Since triggers are disabled, I assumed that postgresql shouldn't care
> about referential integrity in TRUNCATE.

I'm going to say the depends on order of execution. Without seeing the 
code changes you have done there is really no way to determine what the 
exact issue is.

> 
> 
> Dimitris
> 

-- 
Adrian Klaver
adrian.klaver@aklaver.com




pgsql-general by date:

Previous
From: Dominique Devienne
Date:
Subject: CREATE SCHEMA AUTHORIZATION and ALTER SCHEMA OWNER TO
Next
From: Dimitrios Apostolou
Date:
Subject: Re: TRUNCATE ONLY with foreign keys and triggers disabled