Re: Tips on troubleshooting slow DELETE (suspect cascades) - Mailing list pgsql-general

From Tom Lane
Subject Re: Tips on troubleshooting slow DELETE (suspect cascades)
Date
Msg-id 1905752.1705443374@sss.pgh.pa.us
Whole thread Raw
In response to Re: Tips on troubleshooting slow DELETE (suspect cascades)  (Adrian Klaver <adrian.klaver@aklaver.com>)
Responses Re: Tips on troubleshooting slow DELETE (suspect cascades)  (Jim Vanns <jvanns@ilm.com>)
List pgsql-general
Adrian Klaver <adrian.klaver@aklaver.com> writes:
> On 1/16/24 09:45, Jim Vanns wrote:
>> I have a slow (CPU bound) DELETE statement I'm attempting to debug and I 
>> suspect that its actually the ON DELETE CASCADE on the foreign key thats 
>> causing it.

99% of the time, the cause is lack of an index on the foreign key's
referencing columns.  We make you have a unique index on the
referenced columns, because otherwise the FK constraint's semantics
are unclear.  But you're not required to make one on the other side.

>> What I need is a way to see into this statement as it executes to 
>> confirm my suspicion - does anyone have any tips on that?

> Explain:
> https://www.postgresql.org/docs/current/sql-explain.html

Specifically, if EXPLAIN ANALYZE shows a lot of time spent in the
enforcement trigger for the FK, this is likely what's happening.

            regards, tom lane



pgsql-general by date:

Previous
From: hector vass
Date:
Subject: Re: Mimic ALIAS in Postgresql?
Next
From: Rob Sargent
Date:
Subject: Re: Mimic ALIAS in Postgresql?