X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 08C3FD730B for ; Sun, 4 Sep 2005 11:58:03 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 35006-09 for ; Sun, 4 Sep 2005 14:58:00 +0000 (GMT) Received: from window.monsterlabs.com (window.monsterlabs.com [216.183.105.176]) by svr1.postgresql.org (Postfix) with SMTP id 831EDD72D1 for ; Sun, 4 Sep 2005 11:57:58 -0300 (ADT) Received: (qmail 30747 invoked from network); 4 Sep 2005 14:57:38 -0000 Received: from dsl092-071-205.bos1.dsl.speakeasy.net (HELO ?66.92.71.205?) (66.92.71.205) by 0 with SMTP; 4 Sep 2005 14:57:38 -0000 In-Reply-To: <72e966b00509032316166ff0cf@mail.gmail.com> References: <72e966b00509032316166ff0cf@mail.gmail.com> Mime-Version: 1.0 (Apple Message framework v734) Content-Type: text/plain; charset=WINDOWS-1252; delsp=yes; format=flowed Message-Id: Cc: pgsql-performance@postgresql.org Content-Transfer-Encoding: quoted-printable From: "Thomas F. O'Connell" Subject: Re: poor VACUUM performance on large tables Date: Sun, 4 Sep 2005 09:58:01 -0500 To: jan.l.peterson@gmail.com X-Mailer: Apple Mail (2.734) X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0 required=5 tests=[none] X-Spam-Level: X-Archive-Number: 200509/69 X-Sequence-Number: 14377 On Sep 4, 2005, at 1:16 AM, Jan Peterson wrote: > Hello, > > We have been experiencing poor performance of VACUUM in our production > database. Relevant details of our implementation are as follows: > > 1. We have a database that grows to about 100GB. > 2. The database is a mixture of large and small tables. > 3. Bulk data (stored primarily in pg_largeobject, but also in various > TOAST tables) comprises about 45% of our data. > 4. Some of our small tables are very active, with several hundred > updates per hour. > 5. We have a "rolling delete" function that purges older data on a > periodic basis to keep our maximum database size at or near 100GB. > > Everything works great until our rolling delete kicks in. Of course, > we are doing periodic VACUUMS on all tables, with frequent VACUUMs on > the more active tables. The problem arises when we start deleting the > bulk data and have to VACUUM pg_largeobject and our other larger > tables. We have seen VACUUM run for several hours (even tens of > hours). During this VACUUM process, our smaller tables accumulate > dead rows (we assume because of the transactional nature of the > VACUUM) at a very rapid rate. Statistics are also skewed during this > process and we have observed the planner choosing sequential scans on > tables where it is obvious that an index scan would be more efficient. > > We're looking for ways to improve the performance of VACUUM. We are > already experimenting with Hannu Krosing's patch for VACUUM, but it's > not really helping (we are still faced with doing a database wide > VACUUM about once every three weeks or so as we approach the > transaction id rollover point... this VACUUM has been measured at 28 > hours in an active environment). > > Other things we're trying are partitioning tables (rotating the table > that updates happen to and using a view to combine the sub-tables for > querying). Unfortunately, we are unable to partition the > pg_largeobject table, and that table alone can take up 40+% of our > database storage. We're also looking at somehow storing our large > objects externally (as files in the local file system) and > implementing a mechanism similar to Oracle's bfile functionality. Of > course, we can't afford to give up the transactional security of being > able to roll back if a particular update doesn't succeed. > > Does anyone have any suggestions to offer on good ways to proceed > given our constraints? Thanks in advance for any help you can > provide. > > -jan- Do you have your Free Space Map settings configured appropriately? =20 See section 16.4.3.2 of the docs: http://www.postgresql.org/docs/8.0/static/runtime-config.html#RUNTIME-=20= CONFIG-RESOURCE You'll want to run a VACUUM VERBOSE and note the numbers at the end, =20 which describe how many pages are used and how many are needed. =20 max_fsm_pages should be set according to that, and you can set =20 max_fsm_relations based on it, too, although typically one knows =20 roughly how many relations are in a database. http://www.postgresql.org/docs/8.0/static/sql-vacuum.html Finally, have you experimented with pg_autovacuum, which is located =20 in contrib in the source tarballs (and is integrated into the backend =20= in 8.1 beta and beyond)? You don't really say how often you're =20 running VACUUM, and it might be that you're not vacuuming often enough. -- Thomas F. O'Connell Co-Founder, Information Architect Sitening, LLC Strategic Open Source: Open Your i=99 http://www.sitening.com/ 110 30th Avenue North, Suite 6 Nashville, TN 37203-6320 615-469-5150 615-469-5151 (fax)=