Received: from maia.hub.org (maia-2.hub.org [200.46.204.251]) by mail.postgresql.org (Postfix) with ESMTP id 24A26633543 for ; Wed, 9 Jun 2010 03:04:20 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.251]) (amavisd-maia, port 10024) with ESMTP id 64739-01 for ; Wed, 9 Jun 2010 06:04:08 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from moutng.kundenserver.de (moutng.kundenserver.de [212.227.17.10]) by mail.postgresql.org (Postfix) with ESMTP id 61916633DC9 for ; Wed, 9 Jun 2010 03:04:08 -0300 (ADT) Received: from [192.168.0.105] (pool-96-244-14-10.bltmmd.fios.verizon.net [96.244.14.10]) by mrelayeu.kundenserver.de (node=mreu1) with ESMTP (Nemesis) id 0Lvx1t-1PMpRL03jB-018Bpj; Wed, 09 Jun 2010 08:04:06 +0200 Message-ID: <4C0F2ED4.2080102@2ndquadrant.com> Date: Wed, 09 Jun 2010 02:04:04 -0400 From: Greg Smith User-Agent: Thunderbird 2.0.0.24 (X11/20100317) MIME-Version: 1.0 To: Mark Rostron CC: "pgsql-admin@postgresql.org" Subject: Re: optimizer behavior in the case of highly updated tables References: In-Reply-To: Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 8bit X-Provags-ID: V01U2FsdGVkX19401tg9avnhfPPDKaIagHhrmJeGrEfEaoyUXx AykGQVO07Uvye55l3hyM6Q8alGID0zIbzzzdLZXa8tP7NbQRlv JdZD72rC3yGIHfkugvGEhwTJsBLeBQt X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.8 tagged_above=-10 required=5 tests=BAYES_50=0.8, RCVD_IN_DNSWL_NONE=-0.0001 X-Spam-Level: X-Archive-Number: 201006/78 X-Sequence-Number: 34856 Mark Rostron wrote: > > - It was necessary to take a site outage and perform a “vacuum full > analyze” on the table > > - Following this, the query plan reverted to the more efficient btree > lookup > > Clearly, the garbage buildup resulting from transaction activity on > the table is the villain here. > > - Is it possible to calculate expected space usage given row count and > average row size > > - At what point might the ratio of “expected”/”actual” space usage be > able to indicate the need to perform “full vacuum”, or similar maintenance > I think you're right to focus on this part, because with your usage pattern--deleting all old data constantly--you have to get this under control in order for the query planner to do the right thing here. Start by reading http://wiki.postgresql.org/wiki/VACUUM_FULL What you probably should have done in order to return to sane query plans was to run CLUSTER instead of VACUUM FULL. Site would have been down less time, and you actually made some future problems a bit worse by screwing your indexes up some using the problematic FULL. As for measuring what's going wrong here, what you want to do is run this around once a week during a slow period and save the output for analysis: VACUUM VERBOSE; This will give you a bunch of statistics about space usage, including a summary at the end that will tell if there's a serious problem you might already be running into (running out of space in the free space map). Combine that with a look at pg_stat_user_tables and you should have a decent initial statistical picture of what's going on with your data. There are two large scale things you may need to consider if volume on your site expands in the future: 1) Deleting the historical data in smaller chunks and doing an immediate VACUUM afterwards. Perhaps as often as daily. This keeps the amount of dead space VACUUM has to clean up as small as possible, at the expensive of higher site overhead. 2) Start partitioning your tables. This allows you to just DROP old partitions rather than deleting rows from a single master table. It can make this whole class of problem go away. -- Greg Smith 2ndQuadrant US Baltimore, MD PostgreSQL Training, Services and Support greg@2ndQuadrant.com www.2ndQuadrant.us