Re: Slow UPADTE, compared to INSERT

From: William Yu <wyu(at)talisys(dot)com>
To: pgsql-performance(at)postgresql(dot)org
Subject: Re: Slow UPADTE, compared to INSERT
Date: 2003-12-04 19:59:01
Message-ID: bqo3lv$1jdg$1@news.hub.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

Ivar Zarans wrote:
>
> I am experiencing strange behaviour, where simple UPDATE of one field is
> very slow, compared to INSERT into table with multiple indexes. I have
> two tables - one with raw data records (about 24000), where one field

In Postgres and any other DB that uses MVCC (multi-version concurrency),
UPDATES will always be slower than INSERTS. With MVCC, what the DB does
is makes a copy of the record, updates that record and then invalidates
the previous record. This allows maintains a consistent view for anybody
who's reading the DB and also avoids the requirement of row locks.

If you have to use UPDATE, make sure (1) your UPDATE WHERE clause is
properly indexed and (2) you are running ANALYZE/VACUUM periodically so
the query planner can optimize for your UPDATE statements.

In response to

Responses

Browse pgsql-performance by date

  From Date Subject
Next Message Richard Huxton 2003-12-04 20:23:36 Re: Slow UPADTE, compared to INSERT
Previous Message Ivar Zarans 2003-12-04 19:51:21 Re: Slow UPADTE, compared to INSERT