X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (neptune.hub.org [200.46.204.2]) by svr1.postgresql.org (Postfix) with ESMTP id 34795D1B441 for ; Thu, 4 Dec 2003 20:28:52 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (neptune.hub.org [200.46.204.2]) (amavisd-new, port 10024) with ESMTP id 14901-06 for ; Thu, 4 Dec 2003 16:28:22 -0400 (AST) Received: from news.hub.org (news.hub.org [200.46.204.72]) by svr1.postgresql.org (Postfix) with ESMTP id 76791D1B453 for ; Thu, 4 Dec 2003 16:28:20 -0400 (AST) Received: from news.hub.org (news.hub.org [200.46.204.72]) by news.hub.org (8.12.9/8.12.9) with ESMTP id hB4KSKbI057925 for ; Thu, 4 Dec 2003 20:28:20 GMT (envelope-from news@news.hub.org) Received: (from news@localhost) by news.hub.org (8.12.9/8.12.9/Submit) id hB4JwtAg052657 for pgsql-performance@postgresql.org; Thu, 4 Dec 2003 19:58:55 GMT From: William Yu X-Newsgroups: comp.databases.postgresql.performance Subject: Re: Slow UPADTE, compared to INSERT Date: Thu, 04 Dec 2003 11:59:01 -0800 Organization: Hub.Org Networking Services Lines: 16 Message-ID: References: <20031204185751.GA15893@alcaron.ee> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Complaints-To: usenet@news.hub.org User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.5) Gecko/20031007 X-Accept-Language: en-us, en In-Reply-To: <20031204185751.GA15893@alcaron.ee> To: pgsql-performance@postgresql.org X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200312/95 X-Sequence-Number: 4955 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.