Re: slow update but have an index - Mailing list pgsql-general

From Tom Lane
Subject Re: slow update but have an index
Date
Msg-id 29467.998057923@sss.pgh.pa.us
Whole thread Raw
In response to slow update but have an index  (Feite Brekeveld <feite.brekeveld@osiris-it.nl>)
List pgsql-general
Feite Brekeveld <feite.brekeveld@osiris-it.nl> writes:
> fields. So I made a dump, and hacked the dump into SQL statements like:
> update accounting set status = 'C' where seqno = 1566385;
> ....
> and the other 74,000
> This is awfully slow. How come ? The index on the seqno should give
> speedy access to the record.

I see you've already solved your problem, but for the archives here's
a couple of suggestions:

1. Make sure you actually *are* getting an index scan --- use EXPLAIN
on the query to check.  If not, have you VACUUM ANALYZEd lately?

2. Wrap the series of commands into a single transaction to avoid
per-update transaction overhead:
    BEGIN;
    update ...;
    update ...;
    ...
    COMMIT;
This can save a good deal of disk activity, since each commit forces
fsync.

3. Rethink whether you can't accomplish the same thing in fewer SQL
commands.  The overhead of parsing and planning a query is way more
than the time taken to find and update one single record.  So, the
more work done per command, the better.

            regards, tom lane

pgsql-general by date:

Previous
From: Tom Lane
Date:
Subject: Re: Max number of tables in a db?
Next
From: "Jeff Eckermann"
Date:
Subject: Re: assigning result of SELECT in TRIGGER