Received: from localhost (unknown [200.46.204.183]) by postgresql.org (Postfix) with ESMTP id CB6FD650E8C for ; Mon, 30 Jun 2008 17:25:00 -0300 (ADT) Received: from postgresql.org ([200.46.204.86]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 41031-10 for ; Mon, 30 Jun 2008 17:24:53 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from s402.sureserver.com (s402.sureserver.com [216.35.197.71]) by postgresql.org (Postfix) with ESMTP id DB9A8650EA9 for ; Mon, 30 Jun 2008 17:24:55 -0300 (ADT) Received: (qmail 18971 invoked by uid 504); 30 Jun 2008 20:24:53 -0000 Received: from unknown (HELO ?97.0.177.44?) (mailing?lists@70.102.219.22) by ns1.s402.sureserver.com with ESMTPA; 30 Jun 2008 20:24:53 -0000 Subject: Re: Does max size of varchar influence index size From: Mark Roberts To: Franck Routier Cc: pgsql-performance@postgresql.org In-Reply-To: <1214845078.6710.7.camel@franck-laptop> References: <1214845078.6710.7.camel@franck-laptop> Content-Type: text/plain Date: Mon, 30 Jun 2008 13:24:54 -0700 Message-Id: <1214857494.6049.76.camel@localhost> Mime-Version: 1.0 X-Mailer: Evolution 2.12.1 Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.305 tagged_above=0 required=5 tests=AWL=0.305 X-Spam-Level: X-Archive-Number: 200806/249 X-Sequence-Number: 30599 On Mon, 2008-06-30 at 18:57 +0200, Franck Routier wrote: > Hi, > > I have problems with my database becoming huge in size (around 150 GB > right now, and 2/3 for only three tables, each having around 30 millions > tuples. Space is spent mainly on indices.). > > I have a lot of multi-column varchar primary keys (natural keys), and > lot of foreign keys on these tables and thus a lot of indices. > > When using VARCHAR, we defaulted to VARCHAR(32) (because on _some_ of > the identifiers, we have to apply md5). > > We assumed that using VARCHAR(32) but having values at most 4 characters > long (for example) wouldn't influence indices size, ie it would be the > same as using VARCHAR(4) to keep the example. > > Now I really doubt if we were right :) > > So, what should we expect ? And are there other factors influencing > indices size ? > > Thanks, > Franck Is there any particular reason that you're not using a surrogate key? I found that switching from natural to surrogate keys in a similar situation made the indexes not only smaller, but faster. It really only became an issue after our individual tables got larger than 20-25G, but I think we got lucky and headed the issue off at the pass. I think it should be fairly trivial* to set up a test case using pg_total_relation_size() to determine whether your suspicions are correct. -Mark * It may not be as trivial as I say, or I'd have done it in the 5 minutes it took to write this email.