Received: from maia.hub.org (maia-3.hub.org [200.46.204.243]) by mail.postgresql.org (Postfix) with ESMTP id 23CEEB5D801 for ; Tue, 24 May 2011 18:46:16 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.243]) (amavisd-maia, port 10024) with ESMTP id 23827-01 for ; Tue, 24 May 2011 21:46:08 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from moutng.kundenserver.de (moutng.kundenserver.de [212.227.17.9]) by mail.postgresql.org (Postfix) with ESMTP id 53318B5DBD3 for ; Tue, 24 May 2011 18:46:08 -0300 (ADT) Received: from [192.168.1.6] (mail.highperformancepostgresql.com [71.179.240.8]) by mrelayeu.kundenserver.de (node=mrbap2) with ESMTP (Nemesis) id 0M0sl5-1PVvUm2cgR-00uNGC; Tue, 24 May 2011 23:46:07 +0200 Message-ID: <4DDC271E.2020101@2ndQuadrant.com> Date: Tue, 24 May 2011 17:46:06 -0400 From: Greg Smith User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.1.16) Gecko/20110505 Icedove/3.0.11 MIME-Version: 1.0 To: pgsql-performance@postgresql.org Subject: Re: Performance degradation of inserts when database size grows References: In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Provags-ID: V02:K0:thtz2Cm0DiwLzEXHyyV8Xt2qELxte78FFwNYmPXiO17 O0R2oNh6JFxxHxx0ZyzouWNnHs3AZQGSUNoqh7epU1GVcc0X22 1/28IKbibRWymfn7BGwaacP8YqEVjJ9p2gLwr6BxRvLCaMzHJ5 YuakieWug6YwFH28JrYvMyf31TxXW/VGRGsqALxCRbfh1KEHYj dbRgBcgr6J2VMLwN5YCrYDymrmo9+bBMmfYWV0WHoM= X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.9 tagged_above=-10 required=5 tests=BAYES_00=-1.9, RCVD_IN_DNSWL_NONE=-0.0001 X-Spam-Level: X-Archive-Number: 201105/328 X-Sequence-Number: 43837 On 05/17/2011 08:45 AM, Andrey Vorobiev wrote: > 1. How does database size affect insert performance? As indexes grow, it becomes slower to insert into them. It has to navigate all of the indexes on the table to figure out where to add the new row into there, and that navigation time goes up when tables are larger. Try using the queries at http://wiki.postgresql.org/wiki/Disk_Usage to quantify how big your indexes are. Many people are absolutely shocked to see how large they become. And some database designers throw indexes onto every possible column combination as if they were free. > 2. Why does number of written buffers increase when database size grows? > As indexes grow, the changes needed to insert more rows get spread over more blocks too. You can install pg_buffercache and analyze what's actually getting dirty in the buffer cache to directly measure what's changing here. If you look at http://projects.2ndquadrant.com/talks and download the "Inside the PostgreSQL Buffer Cache" talk and its "Sample Queries" set, those will give you some examples of how to summarize everything. > 3. How can I further analyze this problem? This may not actually be a problem in that it's something you can resolve. If you assume that you can insert into a giant table at the same speed you can insert into a trivial one, you'll have to adjust your thinking because that's never going to be true. Removing some indexes may help; reducing the columns in the index is also good; and some people end up partitioning their data specifically to help with this situation. It's also possible to regain some of the earlier performance using things like REINDEX and CLUSTER. -- Greg Smith 2ndQuadrant US greg@2ndQuadrant.com Baltimore, MD PostgreSQL Training, Services, and 24x7 Support www.2ndQuadrant.us "PostgreSQL 9.0 High Performance": http://www.2ndQuadrant.com/books