Simple queries occasionally running very slowly

Posted by Johan on Server Fault See other posts from Server Fault or by Johan
Published on 2010-05-24T16:32:53Z Indexed on 2010/05/24 16:41 UTC
Read the original article Hit count: 319

I have some very simple queries that occasionally run very slowly.

The table viewed_sites has about 10 - 20 rows.

Running EXPLAIN ANALYZE always gives a runtime of less than 3 milliseconds.

When the query is run automatically (every 10 seconds) it occasionally takes over a second to run.

The query:

INSERT INTO ga.viewed_sites (site_id) VALUES ('gop2')

The table:

CREATE TABLE viewed_sites (
    site_id character varying(4) NOT NULL,
    last_viewed timestamp with time zone DEFAULT now() NOT NULL
);

The (occasional) log result:

2010-05-24 15:47:55 UTC LOG: duration: 1044.632 ms statement: INSERT INTO ga.viewed_sites (site_id) VALUES ('gop2')

It's a horribly vague question, but what could be causing this? I suppose it comes down to CPU, RAM, HDD or some combination of the above.

Postgresql 8.3, Ubuntu 8.04

Intel(R) Core(TM)2 Duo CPU E6750 @ 2.66GHz

2 GiB RAM

© Server Fault or respective owner

Related posts about postgresql

Related posts about performance-tuning