Re: Why Does UPDATE Take So Long? - Mailing list pgsql-general

From Jeff Davis
Subject Re: Why Does UPDATE Take So Long?
Date
Msg-id 1222803373.6275.19.camel@dell.linuxdev.us.dell.com
Whole thread Raw
In response to Why Does UPDATE Take So Long?  (Bill Thoen <bthoen@gisnet.com>)
List pgsql-general
On Tue, 2008-09-30 at 13:00 -0600, Bill Thoen wrote:
> Working with PG 8.1 I'm trying to update a char(4) column, and it's
> taking a very long time; 15 minutes so far and no end in sight. From the
> explain, it doesn't seem like it should take that long, and this column
> is not indexed. Sure, there's 2.7 million records but it only takes a
> few minutes to scan the whole file. Is there some special overhead I
> should be aware of with an UPDATE? I VACUUMed and ANALYZEd first, too.
>

In PostgreSQL, think of an UPDATE as an INSERT+DELETE. It's got to write
the new versions of the tuples, and it has to keep the old versions
until there are no more transactions that might reference those old
versions. Imagine if you canceled the query halfway through, for
example. Also, it has to create new index entries for the same reason,
which is expensive.

There are some optimizations in 8.3 for when the same tuple gets updated
many times, but that won't help you in this case.

Regards,
    Jeff Davis




pgsql-general by date:

Previous
From: Felix Homann
Date:
Subject: Re: Alias name from subquery
Next
From: "Scott Marlowe"
Date:
Subject: Re: Why Does UPDATE Take So Long?