Timeline for Very slow DELETE in PostgreSQL, workaround?
Current License: CC BY-SA 3.0
5 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
Dec 19, 2019 at 17:01 | comment | added | kleptog | For those trying to understand why: consider a foreign key from table A to table B. If you delete a row from table B the database has to verify that no rows in table A reference this row. If table A does not have an index on the referencing column, it has to sequentially scan the whole table, which could be very slow if the table is large. | |
Oct 4, 2018 at 17:34 | comment | added | Justin Workman |
This solved it for me as well. For anyone trying this, you can do an EXPLAIN (ANALYZE, BUFFERS) query on a single row delete and it should show you which foreign key constraints took the longest (at least it did for me).
|
|
Aug 4, 2018 at 4:51 | vote | accept | jd. | ||
May 11, 2016 at 20:56 | review | First posts | |||
May 12, 2016 at 8:30 | |||||
May 11, 2016 at 20:53 | history | answered | ailnlv | CC BY-SA 3.0 |