Jonatan Evald Buus <jonatan.buus@cellpointmobile.com> writes:
> We're currently having very poor performance for the following delete query.
> DELETE FROM TopTable WHERE id IN (xx, yy, zz);
> We've observed that it takes around 7 seconds under normal load to for each
> row that's being from TopTable and several minutes pr deleted row under
> heavy load.
I'd really have to bet that you forgot to index one of the referencing
tables. Are any of the foreign keys multi-column? If so you probably
need a matching multi-column index, not just indexes on the individual
referencing columns.
> How do we track down the cause of the poorly performing delete query?
EXPLAIN ANALYZE on a DELETE, for starters. That would isolate whether
it's the DELETE itself or one of the foreign-key updates, and if the
latter which one. It's a little bit difficult to see the exact plan being
used for a foreign-key update query, but I think one way you could do it
is to enable auto_explain with auto_explain.log_nested_statements turned
on.
regards, tom lane