TGM
TGM

Reputation: 1679

PostgreSql delete time exceeded

I have a simple PostgreSQL table with a Primary Key named id and around 20 entries.

The following takes between 60 and 70 seconds to execute.

DELETE FROM user WHERE id = '20'

Simple SELECT queries execute in less than 10 mls which is fine.

When running EXPLAIN over the DELETE query this is the output:

"Seq Scan on user  (cost=0.00..1.26 rows=1 width=6)"
"  Filter: ((id)::text = '20'::text)"

I cannot find any explanation for those delete query taking that long. Is there something I'm missing?

Upvotes: 0

Views: 145

Answers (1)

Ants Aasma
Ants Aasma

Reputation: 54882

One probable cause is that you have a foreign key referencing this table that doesn't have an usable index on the foreign key expression. Because you said that the type of the primary key is irregular the likely cause is that the type of the foreign key doesn't match the type of the primary key.

Edit: I didn't notice at first that your table is so small that the sequential scan is normal.

Upvotes: 1

Related Questions