Re: About the relation between fragmentation of file and

From: David Lang <dlang(at)invendra(dot)net>
To: Richard Huxton <dev(at)archonet(dot)com>
Cc: Tatsumi Abe <sc-abe(at)milan(dot)nri(dot)co(dot)jp>, pgsql-performance(at)postgresql(dot)org
Subject: Re: About the relation between fragmentation of file and
Date: 2005-12-01 12:11:09
Message-ID: Pine.LNX.4.62.0512010355580.2807@qnivq.ynat.uz
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

On Thu, 1 Dec 2005, Richard Huxton wrote:

> Tatsumi Abe wrote:
>> Question is about the relation between fragmentation of file and VACUUM
>> performance.
>>
>> <Environment>
>> OSRedHat Enterprise Linux AS Release 3(Taroon Update 6)
>> Kernel 2.4.21-37.ELsmp on an i686
>> Filesystem Type ext3
>> Filesystem features: has_journal filetype needs_recovery sparse_super large_file

try different filesystems, ext2/3 do a very poor job when you have lots of
files in a directory (and 7000+ files is a lot). you can also try mounting
the filesystem with noatime, nodiratime to reduce the seeks when reading,
and try mounting it with oldalloc (which changes how the files are
arranged on disk when writing and extending them), I've seen drastic
speed differences between ext2 and ext3 based on this option (ext2
defaults to oldalloc, ext3 defaults to orlov, which is faster in many
cases)

>> CPUIntel(R) Xeon(TM) CPU 2.80GHz stepping 01
>> Memory2.0GB
>> HDD80GBS-ATA
>> SATA max UDMA/133
>> PostgreSQL7.3.8
>>
>> <DB Environment>
>> 1. Approx. there are 3500 tables in the DB
>
>> When the performance of inserting data was measured in the above-
>> mentioned environment, it takes six minutes to write 10000 lines
>> after 4/5 days the measurement had begun. While searching the reason
>> of bottleneck by executing iostat command it is understood that DISK I/O
>> was problem for the neck as %iowait was almost 100% at that time.
>>
>> On the very first day processing time of VACUUM is not a problem but
>> when the day progress its process time is increasing.Then I examined the
>> fragmentation of database area(pgsql/data/base) by using the following tools.
>>
>> Disk Allocation Viewer
>> http://sourceforge.net/projects/davtools/
>>
>> Fragmentation rate is 28% before defrag.
>
> I'd guess the root of your problem is the number of tables (3500), which
> if each has one index represents at least 7000 files. That means a lot
> of your I/O time will probably be spent moving the disk heads between
> the different files.

depending on the size of the tables it can actually be a lot worse then
this (remember Postgres splits the tables into fixed size chunks)

when postgres adds data it will eventually spill over into additional
files, when you do a vaccum does it re-write the tables into a smaller
number of files or just rewrite the individual files (makeing each of them
smaller, but keeping the same number of files)

speaking of this, the selection of the size of these chunks is a
comprimize between the time needed to seek in an individual file and the
number of files that are created, is there an easy way to tinker with this
(I am sure the default is not correct for all filesystems, the filesystem
handling of large and/or many files differ drasticly)

> You say you can't stop the server, so there's no point in thinking about
> a quick hardware upgrade to help you. Also a version-upgrade is not
> do-able for you.

there's a difference between stopping the server once for an upgrade
(hardware or software) and having to stop it every few days to defrag
things forever after.

David Lang

> I can only think of two other options:
> 1. Change the database schema to reduce the number of tables involved.
> I'm assuming that of the 3500 tables most hold the same data but for
> different clients (or something similar). This might not be practical
> either.
>
> 2. Re-order how you access the database. ANALYSE the updated tables
> regularly, but only VACUUM them after deletions. Group your inserts so
> that all the inserts for table1 go together, then all the inserts for
> table2 go together and so on. This should help with the fragmentation by
> making sure the files get extended in larger chunks.
>
> Are you sure it's not possible to spend 15 mins offline to solve this?
> --
> Richard Huxton
> Archonet Ltd
>
> ---------------------------(end of broadcast)---------------------------
> TIP 9: In versions below 8.0, the planner will ignore your desire to
> choose an index scan if your joining column's datatypes do not
> match
>
>From pgsql-performance-owner(at)postgresql(dot)org Thu Dec 1 11:42:40 2005
X-Original-To: pgsql-performance-postgresql(dot)org(at)localhost(dot)postgresql(dot)org
Received: from localhost (av.hub.org [200.46.204.144])
by postgresql.org (Postfix) with ESMTP id 8D5629DD693
for <pgsql-performance-postgresql(dot)org(at)localhost(dot)postgresql(dot)org>; Thu, 1 Dec 2005 11:42:39 -0400 (AST)
Received: from postgresql.org ([200.46.204.71])
by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
with ESMTP id 47445-02
for <pgsql-performance-postgresql(dot)org(at)localhost(dot)postgresql(dot)org>;
Thu, 1 Dec 2005 11:42:33 -0400 (AST)
X-Greylist: domain auto-whitelisted by SQLgrey-
Received: from wproxy.gmail.com (wproxy.gmail.com [64.233.184.196])
by postgresql.org (Postfix) with ESMTP id 33AAC9DD684
for <pgsql-performance(at)postgresql(dot)org>; Thu, 1 Dec 2005 11:42:35 -0400 (AST)
Received: by wproxy.gmail.com with SMTP id i23so251782wra
for <pgsql-performance(at)postgresql(dot)org>; Thu, 01 Dec 2005 07:42:41 -0800 (PST)
DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws;
s=beta; d=gmail.com;
h=received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references;
b=E4tCkbGCIfoLMxAWvaMP+9C0TYVeKZ+/7VvYQHsgMWOPJ2NOGn0g076GCQQc5Ze4OD+x1V+8JkkLLB+NcPcD+da+77XwoGaSPgZfo5V0rnsu0nL+5PbEpl628bG8Vvhu8jGGoc7qLq4+4NAdxnZ1kd6+9Jm+BVGX5iUBIVZsFCs=
Received: by 10.65.38.14 with SMTP id q14mr871367qbj;
Thu, 01 Dec 2005 07:42:39 -0800 (PST)
Received: by 10.65.180.14 with HTTP; Thu, 1 Dec 2005 07:42:39 -0800 (PST)
Message-ID: <c2d9e70e0512010742p5e5fb61dx84dfb8e332c05352(at)mail(dot)gmail(dot)com>
Date: Thu, 1 Dec 2005 10:42:39 -0500
From: Jaime Casanova <systemguards(at)gmail(dot)com>
To: Michael Riess <mlriess(at)gmx(dot)de>
Subject: Re: 15,000 tables
Cc: pgsql-performance(at)postgresql(dot)org
In-Reply-To: <dmmujf$2rgd$1(at)news(dot)hub(dot)org>
MIME-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline
References: <dmmujf$2rgd$1(at)news(dot)hub(dot)org>
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, score=0 required=5 tests=[none]
X-Spam-Score: 0
X-Spam-Level:
X-Archive-Number: 200512/15
X-Sequence-Number: 15836

On 12/1/05, Michael Riess <mlriess(at)gmx(dot)de> wrote:
> Hi,
>
> we are currently running a postgres server (upgraded to 8.1) which has
> one large database with approx. 15,000 tables. Unfortunately performance
> suffers from that, because the internal tables (especially that which
> holds the attribute info) get too large.
>
> (We NEED that many tables, please don't recommend to reduce them)
>

Have you ANALYZEd your database? VACUUMing?

BTW, are you using some kind of weird ERP? I have one that treat
informix as a fool and don't let me get all of informix potential...
maybe the same is in your case...

--
regards,
Jaime Casanova
(DBA: DataBase Aniquilator ;)

In response to

Browse pgsql-performance by date

  From Date Subject
Next Message Franklin Haut 2005-12-01 12:29:35 pg_dump slow
Previous Message Michael Stone 2005-12-01 12:00:28 Re: About the relation between fragmentation of file and